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 2000 Forums
 SQL Server Development (2000)
 var=var+''

Author  Topic 

marconi8
Yak Posting Veteran

73 Posts

Posted - 2003-04-28 : 10:52:04
why i cannot use this contruction in my sp

declare @v1 varchar(1000)

@v1 = @v1+'string string'

monkeybite
Posting Yak Master

152 Posts

Posted - 2003-04-28 : 10:56:14
quote:

why i cannot use this contruction in my sp

declare @v1 varchar(1000)

@v1 = @v1+'string string'





You need to set a value for @v1 before concatenating it to a string value. @v1 is NULL until given a value. Plus, your statement should read:
SET @v1 = @v1+'string string'


This is default behavior in SQL Server. Look up "CONCAT_NULL_YIELDS_NULL" in the section "Setting Database Options" in SQL Books Online.

~ monkey


Edited by - monkeybite on 04/28/2003 10:57:09
Go to Top of Page

jsmith8858
Dr. Cross Join

7423 Posts

Posted - 2003-04-28 : 10:56:30
SET @v1 = @v1 + 'string string'

also, if @V1 has no initial value, it will just be Null so any attempt to concatenate to it will always result in a Null ... unless you initialize it first:

declare @v1 varchar(100)

set @v1 = ''
Set @v1 = @v1 + 'string string'




- Jeff
Go to Top of Page

marconi8
Yak Posting Veteran

73 Posts

Posted - 2003-04-28 : 11:06:09
thanks for replay to all

Go to Top of Page
   

- Advertisement -