Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

sql query not printing

Tags:

sql

sql-server

I am trying to run a dynamic query but for some odd reason its not running. Its not even printing. Please can anyone tell me why is the below dynamic query not printing.

DECLARE @CLIENTPK_NEW AS VARCHAR(50)
DECLARE @CGNEEPK AS VARCHAR(50)
DECLARE @TYPE AS VARCHAR(10)

SET @CLIENTPK_NEW='6EF77AAA-1A7B-4D03-A448-D1088DED4134'
SET @CGNEEPK= NULL
SET @TYPE='Mag'

DECLARE @SQL NVARCHAR(MAX)       

SET @SQL = '    
SELECT       
PUBLISHER
FROM CLIENT_SHIPPINGREPORTDATA_FUNCTION('
  + @CLIENTPK_NEW + ' , ' 
  + @CGNEEPK + ' , ' 
  + @TYPE +' )' <=== This is the troubled line, but not sure what is error is.

PRINT  @SQL    <== **Why is this not priniting**

Many thanks

like image 480
Amit Avatar asked Dec 03 '22 04:12

Amit


1 Answers

You are adding string values to a null value (@CGNEEPK) which results in NULL. When you print NULL, you see nothing. You need to use ISNULL(@CGNEEPK, '') instead.

like image 103
Daniel Renshaw Avatar answered Dec 22 '22 12:12

Daniel Renshaw