Click to See Complete Forum and Search --> : how to use "PRINT" in this store procedure?


mr_newbie
02-19-2010, 07:49 PM
Hi, im using the code below in a store procedure. It is meant to print some text if the column in question does not equal 0.

But its giving me an error because i think the quotation marks are conflicting with the quotations from the SET @SQLSTRING='
How would you use PRINT in this situation?

Thanks


SET @SQLSTRING=

'

PRINT 'The results are as follows:'

IF (SELECT SUM(Col1) FROM Table) <> 0 PRINT 'Col1 false'
IF (SELECT SUM(Col2) FROM Table) <> 0 PRINT 'Col2 false'
IF (SELECT SUM(Col3) FROM Table) <> 0 PRINT 'Co3 false'

'
EXEC SP_EXECUTESQL @SQLSTRING

ssystems
03-03-2010, 03:40 PM
Escape it.



create procedure [test]
as
declare @sqlstring as varchar(max)
set @sqlstring = 'Print ''test'''
exec(@sqlstring)



notice the ''