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 |
learning_grsql
Posting Yak Master
230 Posts |
Posted - 2014-02-15 : 03:51:28
|
The below code works fine. It displays the column orgid in a single row. But when I remove the group by clause from the code, it shows output "NULL". I wonder why and how group by clause affects the output.use ebusiness godeclare @orgname varchar(max)select @orgname = coalesce(@orgname,'') + orgid + ','from org group by orgidselect @orgname |
|
SwePeso
Patron Saint of Lost Yaks
30421 Posts |
Posted - 2014-02-15 : 04:35:01
|
To get the distinct values of OrgID, just in case there are duplicates. Microsoft SQL Server MVP, MCT, MCSE, MCSA, MCP, MCITP, MCTS, MCDBA |
|
|
learning_grsql
Posting Yak Master
230 Posts |
Posted - 2014-02-15 : 05:25:32
|
Thanks SwePeso. But I know that. My concern is why it produces output "NULL" when I don't add 'group by". What makes it to give only NULL ? |
|
|
kennejd
Starting Member
11 Posts |
Posted - 2014-02-26 : 15:54:49
|
Just wondering....is it possible there is a row in the table that has a Null OrgId? I wouldn't think so, but that's what I would check. |
|
|
|
|
|