dbTalk Databases Forums  

Re: Concatinate two variables in sql server

comp.databases.ms-sqlserver comp.databases.ms-sqlserver


Discuss Re: Concatinate two variables in sql server in the comp.databases.ms-sqlserver forum.



Reply
 
Thread Tools Display Modes
  #1  
Old   
Greg D. Moore \(Strider\)
 
Posts: n/a

Default Re: Concatinate two variables in sql server - 07-28-2003 , 08:51 AM







"T.S.Negi" <tilak.negi (AT) mind-infotech (DOT) com> wrote

Quote:
I have two variables, and when I'm concatinating both of them, if any
of them is not having value the result string becomes empty.
I want to concatinate variables, like it happens in Visual basic.

even if some of the variables are not having value it still return the
result.


problem description.

DECLARE @A VARCHAR(200)
DECLARE @B VARCHAR(200)
DECLARE @C VARCHAR(200)
SET @A='AAA'
--NO SET FOR @B (SET @B='BBB')
SET @C=@A+@B
PRINT @C


... I WANT @C SHOULD RETURN ME AAA

BUT ITS GIVING ME BLANK.
Concatenation of NULL fields results in a NULL.

As @B is NULL, concatenation of @A results in a NULL.


Quote:

THANX IN ADV.

T.S.NEGI
(MIND)



Reply With Quote
  #2  
Old   
CJ
 
Posts: n/a

Default Re: Concatinate two variables in sql server - 07-28-2003 , 05:29 PM






Maybe the ISNULL function is what you are looking for.

DECLARE @A VARCHAR(200)
DECLARE @B VARCHAR(200)
DECLARE @C VARCHAR(200)
SET @A='AAA'
--NO SET FOR @B (SET @B='BBB')
SET @C=@A+@B
SET @C=ISNULL(@B,@A)
SELECT @c

CJ


"T.S.Negi" <tilak.negi (AT) mind-infotech (DOT) com> wrote

Quote:
I have two variables, and when I'm concatinating both of them, if any
of them is not having value the result string becomes empty.
I want to concatinate variables, like it happens in Visual basic.

even if some of the variables are not having value it still return the
result.


problem description.

DECLARE @A VARCHAR(200)
DECLARE @B VARCHAR(200)
DECLARE @C VARCHAR(200)
SET @A='AAA'
--NO SET FOR @B (SET @B='BBB')
SET @C=@A+@B
PRINT @C


... I WANT @C SHOULD RETURN ME AAA

BUT ITS GIVING ME BLANK.


THANX IN ADV.

T.S.NEGI
(MIND)



Reply With Quote
Reply




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.3
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.