Reputation: 11
I have a table which contains data of ledger. it contains field Account name,debit credit. the data entered in the table at end of month ie. sum of all the days.
Here my problem is that i want to display data of two months i.e current month and the back month. the real problem is that it will be displayed in crosstab
Accname dated debit credit
------- ----- ------ ------
Account name will be in both the months and i want to display one entry from both the month and its corresponding data ie credit and debit field will fill. The query will work on two conditions fields the account name and dated which is to be checked.
Is it possible to use case statement in the query
PLease Help
Upvotes: 1
Views: 49
Reputation: 56697
SQL Server/SQL does not display anything by default. So it doesn't really matter in what form you return the data from your query, as long as it is then visualized the way you want it. Just write your query to return the required data and then care about the visualization.
It might also help us if you told us how you're planning to visualize the data.
To answer your question: Yes, you can use CASE
within a query as in
SELECT
CASE WHEN <Condition1> THEN <Value1>
WHEN <Condition2> THEN <Value2>
ELSE <Value3>
END AS <FieldName>
Upvotes: 1