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 |
ericny
Starting Member
2 Posts |
Posted - 2007-02-13 : 00:45:22
|
I have data that looks like this:ID Value1 Descr11 Descr21 Descr3where Descr could range from 1 to 100 for each IDThe result set I need is:Descr1,Descr2,Desc3...etc.Thank you |
|
SwePeso
Patron Saint of Lost Yaks
30421 Posts |
Posted - 2007-02-13 : 00:59:04
|
Please remember that these concatenated strings only can hold 8000 characters.declare @s varchar(8000)select @s = left(isnull(@s + ',', '') + x.value, 8000)from (select top 100 percent distinct value from yourtable1 order by value) as xselect @sPeter LarssonHelsingborg, Sweden |
|
|
khtan
In (Som, Ni, Yak)
17689 Posts |
|
ericny
Starting Member
2 Posts |
Posted - 2007-02-15 : 23:30:18
|
Thank you. Basically I came up with the following:DROP FUNCTION dbo.ConcatDescrgoCREATE FUNCTION dbo.ConcatDescr(@TXRCODE CHAR(8))RETURNS VARCHAR(300)ASBEGIN DECLARE @Output VARCHAR(300) SET @Output = '' SELECT @Output = CASE @Output WHEN '' THEN MON_TEXT ELSE @Output + ', ' + MON_TEXT END FROM PCLONG WHERE TXRCODE = @TXRCODE order by MON_PCH RETURN @OutputENDGOSELECT TXRCODE, dbo.ConcatDescr(TXRCODE)FROM PCLONG WHERE TXRCODE = '01100008'The code above works to concatenate lines into one however it truncates data after 256 characters. I looked in help and it says that varchar can be up to 8000 chars. Is there something I am doing wrong?Thank you again.EricNYwww.zipdrugs.com |
|
|
harsh_athalye
Master Smack Fu Yak Hacker
5581 Posts |
Posted - 2007-02-15 : 23:33:42
|
"Is there something I am doing wrong?"Yes, but it has nothing to do with your query. In Query Analyzer, Tools, Options, Results tab, set Maximum characters per column to some higher value, say, 8192.Harsh AthalyeIndia."The IMPOSSIBLE is often UNTRIED" |
|
|
|
|
|
|
|