Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Concatenation 1

Status
Not open for further replies.

bikerboy718

Programmer
Feb 11, 2005
195
US
I was wondering if anyone know how I can concatenate a column in SQL Server. I a comments field that I have to include in an email for all comments that were made for a particular order. This is what i have so far:

Code:
declare @msg nvarchar(4000), @temp nvarchar(400)  
declare @RowCnt int, @RC INT, @MaxRows int 
declare @TBL_remarks table	(rownum int IDENTITY (1, 1) Primary key NOT NULL 
							,remarks nvarchar(800))
insert	@TBL_remarks
select remarks from orderitemhold
where	orderitemid = 5770420

select @RowCnt = 1 
select @maxRows = count(*) from @TBL_Remarks


while @rowCnt <= @maxRows
begin
	Select @temp = Remarks from @TBL_remarks where rownum = @rowCnt 
	select @msg = @msg + @temp
	Select @RowCnt = @RowCnt + 1 
end
select @msg


This is what I tried but I get a null value for the variable @msg. Any help is greatly appreciated.



With Great Power Comes Great Responsibility!!! [afro]

Michael
 
Hey that worked perfectly. Is there a reason why you have to initally set the @msg variable to a no space.

With Great Power Comes Great Responsibility!!! [afro]

Michael
 
I got you. I did not know that that was the case here. Thanks for your help.




With Great Power Comes Great Responsibility!!! [afro]

Michael
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top