Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2008 Forums
 Transact-SQL (2008)
 Need a query to get follwing output

Author  Topic 

dattu_reddy06
Starting Member

2 Posts

Posted - 2010-07-18 : 03:12:18
Hi All

I am not that much strong in SQL. Is there any chance i get the output in the way i desire.

I have 3 Tables A, B, C

Table A

ID(PK) Name Place
1 Tom NJ
2 Shaun NY
3 Kim CT


Table B

ID(PK,FK) OrderType(PK) Cost
1 CASH 300
1 cheque 5000
1 online transfer 3000
2 cash 500
3 online transfer 700
3 cheque 200


Table C

ID(PK,FK) PlacesLived (PK) Days
1 nj 300
1 ny 200
2 ct 50
2 ca 200


i need the ouput like this..

ID Name Place OrderType Cost PlacesLived Days
1 Tom NJ CASH 300 nj 300
null null null cheque 5000 ny 200
null null null online transfer 3000 null null
2 Shaun NY cash 500 ct 50
null null null null null ca 200
3 Kim CT online transfer 7000 null null
null null null cheque 200 null null



Can we get like this.... or what is the query which can get output atleast nearer to this...
i dont want values to repeat in columns like cost, ordertype repeated...

If we cannot get like this.....

Even if we get in CSV (below) .. i think it may help me... but priority is for the top shown output..

ID Name Place OrderType-Cost PlacesLived - Days
1 Tom NJ CASH-300,cheque-5000, nj -300,ny -200
onlinetransfer-3000

2 Shaun NY cash - 500 ct - 50,ca -200

3 Kim CT online transfer-7000, null
cheque -200

Thanks in Advance..

Waiting for the reply Guys.......


Dattu

pk_bohra
Master Smack Fu Yak Hacker

1182 Posts

Posted - 2010-07-18 : 11:13:00
Are you going to present the output in any report in front end ?

I am here to learn from Masters and help new bees in learning.
Go to Top of Page

dattu_reddy06
Starting Member

2 Posts

Posted - 2010-07-18 : 16:22:33
I want that to get in a table... so that i can bind that table to gridview and also show that table in an excel... i know how to convert datatable to excel in .net

Dattu
Go to Top of Page
   

- Advertisement -