Click here to Skip to main content
15,921,203 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Here is my code:

SET @MyParameterEntry = 'My first parameter is:   ' + @P1  + ' My second parameter is:   ' + @P2 + 'My third parameter is:  ' + @P3


Print @MyParameterEntry 

When my P3 parameter is NULL, none of my other parameters display - not even my "My first parameter is: " verbiage.

This has not been happening and I am usually able to successfully pass in null or blank parameters and still have my other verbiage print. If I default my P3 parameter to a specific string, the entire @MyParameterEntry variable displays.

What is causing this and how can I resolve it so my entire @MyParameterEntry displays regardless of when my P3 parameter is null?

What I have tried:

Google search, MSDN, compared to other code that works.
Posted
Updated 14-Feb-17 4:02am

Add

isnull(@P3,'')


So blank string so passed rather than a null value. Might be safer to do it to all parameters.
 
Share this answer
 
v2
Comments
Karthik_Mahalingam 2-Feb-17 3:27am    
5
Hi,

Please try this:-
Use Concat in SQL Server
Declare @P1 varchar(10),@P2 varchar(10),@P3 VARCHAR(10),@MyParameterEntry VARCHAR(120)

SET @P1='W'
SET @P2='E'
SET @P3 =NULL


SET @MyParameterEntry = CONCAT( 'My first parameter is: ' , @P1 , ' My second parameter is: ' , @P2 , 'My third parameter is: ' , @P3)


Print @MyParameterEntry
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900