简体   繁体   中英

Select where like is not working, throwing an error message 207

I'm trying to query the database from Visual Studio 2017 using T-SQL. The query is:

Select * 
From table 
Where columnname like '0%'

The error message is as follows:

Msg 207, Level 16, State 1, Line 1
Invalid column name '0%'.

The like clause is greyed in the console for some reason, it is not blue like the others.

I would like to get all records whose byte starts with 0 eg:

SELECT JobFileName 
FROM JobImages 
WHERE JobFileName LIKE "0%"

Wrong quotes. Double quotes "0%" are used to wrap column names.

Use a single quote '0%' instead

In SQL Server with SET QUOTED_IDENTIFIER ON the double quotes are used to delimit identifiers (database, column and table names etc). Use single quotes to delimit strings - this works regardless of SET QUOTED_IDENTIFIER setting:

SELECT JobFileName FROM JobImages WHERE JobFileName LIKE '0%'

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM