Click here to Skip to main content
15,890,741 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi All,

SQL
SELECT * FROM MyTable WHERE Title like 'PR%'       


The above query will give me the result set of records having title starting with 'PR'
example: Price,PRofit,Predict etc.

but instead of PR hard coded I'll get it in a variable say @Title = 'PR' based on which I need to filter
SELECT * FROM MyTable WHERE Title like @PR %

This is throwing error.

Could you please help me in this to query

Thanks & Regards,
Mathi.
Posted

Try like below...
SQL
SELECT * FROM MyTable WHERE Title like @PR + '%'
 
Share this answer
 
Comments
Mathi2code 9-May-13 0:19am    
Thanks Tadit....
Most Welcome... My pleasure. :)

Thanks for accepting the answer,
Tadit
SQL
DECLARE @sqlQuery nVARCHAR(500)
        SET @sqlQuery = 'SELECT * FROM #tempSectionDetails WHERE Title like '''+@Title+ '%' + '''ORDER BY Title'

        EXECUTE sp_executesql @sqlQuery


Even this worked for me....
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900