Mathematics
Mathematics

Reputation: 7618

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'.

Upvotes: 3

Views: 11176

Answers (2)

Use <>, Replace " with single quotes ' Problem Identifier marc_s thanks

WHERE Table.ColumnName <> 'string' or Table.ColumnName is null

Also i think for not like

where Table.ColumnNamenot like '%string%'

Upvotes: 0

marc_s
marc_s

Reputation: 754468

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'

Upvotes: 5

Related Questions