Click here to Skip to main content
15,888,610 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more: , +
I have following Result in sql server From table and table name is DailyCash

Amount Company PaymentMode
88659 Head Office CASH
95879.50 Head Office CREDIT CARD
93.00 Branches CASH
33.50 Branches CREDIT CARD

so i want result like that

Head Office
88659 / Cash
95879 / Credit Card

Branches
93 / cash
33.50 / Credit card

What I have tried:

how i can write sql query for this type of result
Posted
Updated 3-Jul-19 0:28am

1 solution

SQL
SELECT Amount, PaymentMode FROM DailyCash WHERE Company = 'Head Office';
SELECT Amount, PaymentMode FROM DailyCash WHERE Company = 'Branches';

But ... that's a very poor design. You shouldn't bew sorting "Company" or "PaymentMode" as strings: they should be in two separate tables each with an IDENTITY based ID column which you reference via a Foreign Key from your DailyCash table, via a JOIN.

Doing it your way both wastes space (strings are bigger than IDs) and encourages errors as the string field could be badly entered: 'Heed Office' or 'CEDIT CARD' for example.
 
Share this answer
 

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