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.

 All Forums
 SQL Server 2005 Forums
 Transact-SQL (2005)
 Concatenate two variables

Author  Topic 

DivineWind
Starting Member

2 Posts

Posted - 2007-03-15 : 17:17:59
I am looking to concatenate two variables. For example, I would like the following to happen:

DECLARE @BODY1 AS VARCHAR(300)
DECLARE @ID VARCHAR(6)

WHILE [statement]
SET @BODY1 = @BODY1 + @ID
END

Any ideas on how to do this? Thank you.

jezemine
Master Smack Fu Yak Hacker

2886 Posts

Posted - 2007-03-15 : 18:23:09
string concat is with the '+' operator as you have written.

however your code makes little sense to me because @body and @id are never initialized to anything so they will always be NULL.

also remember that something + null = null. so even if you initialized @body, it would be set to null in your loop since @id is uninitialized.


www.elsasoft.org
Go to Top of Page

DivineWind
Starting Member

2 Posts

Posted - 2007-03-16 : 09:58:18
quote:
Originally posted by jezemine

string concat is with the '+' operator as you have written.

however your code makes little sense to me because @body and @id are never initialized to anything so they will always be NULL.

also remember that something + null = null. so even if you initialized @body, it would be set to null in your loop since @id is uninitialized.


www.elsasoft.org



The point about + null = null is where the problem was happening... I did not initialize the variable. The problem is fixed now. Thank you very much.
Go to Top of Page

ASIF-XEENA
Starting Member

1 Post

Posted - 2010-12-31 : 04:55:35
Check This Code..........................

DECLARE @BODY1 AS VARCHAR(300)
DECLARE @ID VARCHAR(6)
SET @BODY1='string'
SET @ID='0024214'

SET @BODY1 = @BODY1 + @ID
select @BODY1


PAKKAPAKKI
Go to Top of Page
   

- Advertisement -