Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2005 Forums
 Transact-SQL (2005)
 "" '' quotes

Author  Topic 

jamesdwhite
Starting Member

9 Posts

Posted - 2007-02-17 : 18:32:15
Hi i have the following statement:

PROCEDURE [dbo].[xx](@OrderByClause nchar(30) = 'request_id', @request_title nvarchar(150) = NULL)

AS
DECLARE @SQLStatement nvarchar(1000)

SELECT @SQLStatement = '

SET NOCOUNT ON;

IF ' + @request_title + ' IS NOT NULL
SELECT request_id, request_ref_number, request_title, request_status_id, request_function_group_id, request_estimated_effort, request_increment_id, request_notes
FROM Requests
WHERE request_title LIKE '%' + @request_title + '%'
ORDER BY ' + @OrderByClause
EXEC(@SQLStatement)

Now the problem is the quotes ?? how can iescape them so that the LIKE statment is in the correct format?

thanks

Vinnie881
Master Smack Fu Yak Hacker

1231 Posts

Posted - 2007-02-17 : 19:21:13
use two "'" in code that simulates a single '.

So
WHERE request_title LIKE '%' + @request_title + '%'
shouldbe
WHERE request_title LIKE ''%' + @request_title + '%'''

Go to Top of Page
   

- Advertisement -