www.webdeveloper.com
Results 1 to 2 of 2

Thread: how to use "PRINT" in this store procedure?

  1. #1
    Join Date
    Mar 2007
    Posts
    34

    how to use "PRINT" in this store procedure?

    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

    Code:
    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

  2. #2
    Join Date
    Oct 2009
    Posts
    658
    Escape it.

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

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center



Recent Articles