I don't know if this is possible, but here goes;
I need to pull sales data out of SQL into Access or Excel to run in a Pivot Table. I am currently doing this by querying SQL with an Access Database and then imoprting that data into Excel to pivot. It takes literally hours to refresh this pivot. I would like to create a SQL View to help speed this process along. The problem is that Debits and Credits are both put into my SQL database as positive numbers. I am pulling only these two types of sales entries.
What I would like to do is this: iif(dbo.table.type = "credit", dbo.table.dollaramount, dbo.table.dollaramount * -1)
This would pull all of my credits as positive numbers and my debits as negative numbers. Is there a way to write this in a SQL query instead of using Access?
Something like this, using CASE:
Code Snippet
SELECT MyField = CASE
WHEN dbo.table.type = 'Credit' THEN ( dbo.table.dollaramount * (-1) )
ELSE dbo.table.dollaramount
ELSE
FROM MyTable
Excellent! With a little massaging, this seems to be what I am needing. This is what I used:
Code Snippet
SELECT table.type, table.docnumbr, table.itemnmbr, table.itemdesc, 'GROSSSALE' =
CASE
WHEN type = 4 THEN (table.XTNDPRCE * (-1) )
ELSE (table.XTNDPRCE)
END
from table
where type = 3 or type = 4
I think I am going to try to incorporate an Inner Join now.
Again, thanks for your help with this.
-Jody
No comments:
Post a Comment