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 |
|
paull
Yak Posting Veteran
50 Posts |
Posted - 2009-06-04 : 10:03:54
|
| Hi allI really hope you can help!I am creating a report listing out comments from a table called Verbs. The report format is this....:ID Country Variable Comment111 UK V1 Blah blah112 France V1 hello113 UK V2 The quick brown fox113 UK V3 jumped over the lazy dogHowever the source table is as such...:ID | V1 | V2 | V3 | Country111| Blah Blah | Null | Null | UK112| hello | Null | Null | France113| Null | The quick etc | jumped over etc| UKObviously, I wouldn't list out the nulls.I started going down the Case when not null route but got completely confused!!!Any help would be greatly appeciatedThanksP |
|
|
khtan
In (Som, Ni, Yak)
17689 Posts |
Posted - 2009-06-04 : 10:11:49
|
if you are using SQL Server 2005 check out the pivot operator KH[spoiler]Time is always against us[/spoiler] |
 |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2009-06-04 : 13:07:13
|
| [code]SELECT ID,Country,MAX(CASE WHEN Variable='V1' THEN Comment ELSE NULL END) AS V1,MAX(CASE WHEN Variable='V2' THEN Comment ELSE NULL END) AS V2,MAX(CASE WHEN Variable='V3' THEN Comment ELSE NULL END) AS V3FROM TableGROUP BY ID,Country[/code] |
 |
|
|
wjohnson16
Starting Member
5 Posts |
Posted - 2009-06-05 : 12:36:19
|
| ***This will check to see, if data is null then plug in your on words like no comments as substitue for null dataselect ID,Country,isnull(V1, 'No Comments')as Variable1, isnull(v2, 'No Comments')as Variable2,isnull(v2, 'No comments')as Varaible3 from source |
 |
|
|
|
|
|
|
|