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 SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

+= operator equivalent 1

Status
Not open for further replies.

ksbrace

Programmer
May 13, 2000
501
0
0
US
Hello,
I'm trying to append varchar values to an existing varchar in a loop. I was looking for somethign like the '+=' operator that is used in a lot of programming languages. Thanks in advance.

 
Unfortunately, SQL Server does not understand those nice little shortcuts that we all picked up from other languages ( the ones I miss the most are "++" and "--" ). Try, this it should work for you. Also, remember, any value added, subtracted, mutliplied etc.... to a null value will end up as null.

DECLARE @test varchar( 20 )
DECLARE @inx int

SELECT @test = 'A'
SELECT @inx = 0

WHILE( @inx <= 5 )
BEGIN
SELECT @test = @test + 'B'
SELECT @inx = @inx + 1
SELECT @test
END



jimmY
 
jimmmY,
Thanks... I had that, but I didn't initialize my variable to something. After I initialized it to &quot;&quot;, everything went as expected.

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top