Click here to Skip to main content
16,015,177 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
C#
I have this tables "CashMovementTbl","SalesTbl" & "ExpensesTbl" which include data like that:


http://i.stack.imgur.com/koH6C.jpg[^]

And I want to show my data such as following:

http://i.stack.imgur.com/0jPAl.jpg[^]

So how can I do a query in SQL Server to show data like that.
Posted

1 solution

Hi,

Check the Script....
SQL
SELECT CM.CashDate, 
	CASE WHEN CM.CashType='IN' THEN S.BillNo ELSE E.ExpnsType END 'Details',
	CASE WHEN CM.CashType='IN' THEN CM.Amount ELSE 0.000 END 'In',
	CASE WHEN CM.CashType='Out' THEN CM.Amount ELSE 0.000 END 'Out'
FROM CashMovementTbl CM
LEFT OUTER JOIN SalesTbl S ON S.SalesID=CM.SalesID
LEFT OUTER JOIN ExpendesTbl E ON E.ExpnsID=CM.ExpenseID


Regards,
GVPrabu.
 
Share this answer
 
Comments
Doudy_2020 25-Apr-13 15:08pm    
Thanks alot GVPrabu, that 's work fine with me :D
gvprabu 26-Apr-13 3:15am    
welcome :-)

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900