September 12, 2007 at 5:07 am
Hi There,
Im having the problem when i tried to update the value in the column.
My table has following columns,
ID Degree
C111 BSC
C111 MSC
ID acts as a Primary Key
I need to make this 2 rows as a single row
as
C111 BSC,MSC
Can any one help me out with this
Cheers,
Vidhya
September 12, 2007 at 5:18 am
SELECT DISTINCT t1.ID , STUFF(( SELECT DISTINCT TOP 100 PERCENT ',' + t2.Degree FROM degrees AS t2 WHERE t2.ID = t1.ID ORDER BY ',' + t2.Degree FOR XML PATH('') ), 1, 1, '') AS Blah FROM degrees AS t1 ORDER BY t1.ID
Also have a look at http://www.sqlservercentral.com/forums/shwmessage.aspx?forumid=338&messageid=391111
Regards,
Andras
September 12, 2007 at 7:05 am
HI Yeh,
I tried creating a function to hold the values from the select statement.
When they are executed separately they are fine but when used to return table they are thowring the error
Msg 8152, Level 16, State 10, Line 1
String or binary data would be truncated.
The statement has been terminated.
CAN any one help and explain why this is failing.
CREATE FUNCTION DUP()
RETURNS
@DUPLICATE TABLE
(
CODE nVARCHAR(20),CIPHER nVARCHAR(20))
AS
BEGIN
INSERT
INTO @DUPLICATE(CODE,CIPHER)
SELECT
DISTINCT CODE
,
LTRIM( STUFF(( SELECT DISTINCT TOP 100 PERCENT ',' + t2.cipher FROM Duplicate_Rank_List AS t2
WHERE t2.Code = t1.code ORDER BY ',' + t2.cipher FOR XML PATH('') ), 1, 1, ''))
FROM
Duplicate_Rank_List
AS t1
ORDER
BY t1.code
RETURN
END
SELECT
* INTO Mytab FROM DUP()
September 12, 2007 at 7:20 am
You should increase the column lengths in your
"(CODE nVARCHAR(20),CIPHER nVARCHAR(20))"
to more
e.g.:
(CODE nVARCHAR(1000),CIPHER nVARCHAR(1000))
so that it can hold the concatenated results,
Regards,
Andras
October 3, 2008 at 8:34 pm
vidhyasudha (9/12/2007)
Hi There,
Im having the problem when i tried to update the value in the column.
My table has following columns,
ID Degree
C111 BSC
C111 MSC
ID acts as a Primary Key
I need to make this 2 rows as a single row
as
C111 BSC,MSC
Can any one help me out with this
Cheers,
Vidhya
My word, no... if you want to create a report like this, that's one thing... stored CSV data in a database is another and it's the very, very thing to do. The proper thing to do, in this case, is to create the proper primary key. 😉
--Jeff Moden
Change is inevitable... Change for the better is not.
Viewing 5 posts - 1 through 4 (of 4 total)
You must be logged in to reply to this topic. Login to reply