Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

SQL Column not equal to string

In a stored procedure I want to check if a column value is not equal to a string, but not seem to work and I get syntax error.

This is what I am trying,

WHERE Table.ColumnName != "someText"

I also tried,

WHERE Table.ColumnName IS NOT LIKE "string"

Error:

Invalid column name 'someText'.

like image 257
Mathematics Avatar asked Jul 30 '26 11:07

Mathematics


1 Answers

Replace the double quotes " with single quotes ' - then both snippets should work just fine.

WHERE Table.ColumnName != 'someText'

or

WHERE Table.ColumnName <> 'someText'

or

WHERE Table.ColumnName IS NOT LIKE 'someText'

What is the datatype of your column? If it's NVARCHAR, you might need to use a N prefix to signal Unicode: WHERE Table.ColumnName <> N'string'

like image 125
marc_s Avatar answered Aug 02 '26 01:08

marc_s



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!