Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I use Char(39) in a sql statement where clause?

Tags:

sql

sql-server

I am using SQL Server 2008 R2. I am trying to create a recordset based off a sql statement. In the WHERE clause is 'INTERNATIONAL PEOPLE' + Char(39) + 'S'. So the single quote makes it PEOPLE'S. This is failing. From research it seems this should not fail. Any help would be great. Thanks

like image 621
Jamie Colville Avatar asked Mar 18 '26 14:03

Jamie Colville


2 Answers

You can escape single quote by single quote :)

WHERE field = 'INTERNATIONAL PEOPLE''S'
like image 196
Hamlet Hakobyan Avatar answered Mar 20 '26 06:03

Hamlet Hakobyan


From your sample in a comment, I'm guessing it's because your table is named 1099 and the error is not really from your WHERE clause. T-SQL expects table names to start with an alpha character.

Try putting brackets around that:

SELECT * FROM [1099] WHERE Name ='INTERNATIONAL PEOPLE' + CHAR(39) + 'S'
like image 33
ThinkingStiff Avatar answered Mar 20 '26 07:03

ThinkingStiff



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!