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.
| Author |
Topic |
|
Sarakumar
Posting Yak Master
108 Posts |
Posted - 2009-05-10 : 22:08:22
|
| declare @Customer table (cid int,item varchar(50),in_use bit)insert into @Customer values (1,'mobile',0)insert into @Customer values (1,'TV',1)insert into @Customer values(1,'Comp',1)insert into @Customer values(1,'Laptop',0)insert into @Customer values(2,'mobile',0)insert into @Customer values(2,'TV',1)insert into @Customer values(2,'Comp',0)insert into @Customer values(2,'Laptop',1)SELECT cid, [mobile],[TV], [Comp],[Laptop]from(select cid, item ,in_use from @Customer ) stpivot(count(item) for item in([mobile],[TV], [Comp],[Laptop]))PT order by cidHai, With the help of our people in the forum, i could write the above pivot query..But now, i have added new column called in_use in the table, an i want to result to be like the following..cid mobile tv comp laptop1 no yes yes NO2 No Yes No Yesi dont know how to write the query.Help pls |
|
|
khtan
In (Som, Ni, Yak)
17689 Posts |
Posted - 2009-05-10 : 22:13:15
|
change to( select cid, item from @Customer where in_use = 1 ) st KH[spoiler]Time is always against us[/spoiler] |
 |
|
|
Sarakumar
Posting Yak Master
108 Posts |
Posted - 2009-05-10 : 22:31:02
|
| Thanks...it works... |
 |
|
|
|
|
|
|
|