If you had looked at the query you were generating, you would have seen that it is missing the required single quotes. Also, there is really no point in using a like withour wildcards.Select * From NorthWind..Customers Where PostalCode Like T2F 8M4
What you need is something like this:Select * From NorthWind..Customers Where PostalCode Like '%T2F 8M4%'
Try this code:Declare @SQL varchar(1000), @pCode nvarchar(10)Set @pCode = 'T2F 8M4'Set @SQL = 'Select * From NorthWind..Customers Where PostalCode Like ''%'+CAST(@pCode As nvarchar(10))+'%'''Execute (@SQL)
quote:
Originally posted by AskSQLTeam
Kobus writes "I have a stored procedure that gives me the same problem as the following query:Declare @SQL varchar(1000), @pCode nvarchar(10)Set @pCode = 'T2F 8M4'Set @SQL = 'Select * From NorthWind..Customers Where PostalCode Like '+CAST(@pCode As nvarchar(10))+''Execute (@SQL)Why does this query only accept numeric values - replacing 'T2F 8M4' with '12209' gives the correct result?Regards"