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
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With