CASE WHEN语句语法错误求助:SQL Server表字段更新问题
Fixing Your SQL Update Syntax Error
Let's break down what's causing your errors and fix the query:
The Issues in Your Original Code
- Unclosed Quotation Mark: The last value in your
INlist ('000999鈥�') has a mangled character instead of a proper closing single quote. This is the primary cause of theUnclosed quotation markerror. - Parser Confusion: Because of the unclosed quote, the SQL parser got confused and threw a secondary error about the
WHEREkeyword (even though you don't have one in your query)—this is just a side effect of the first issue.
Corrected SQL Query
Here's the fixed version that does exactly what you need:
UPDATE [dbo.industry] SET areatype = CASE WHEN area IN ('000995', '000996', '000998', '000999') THEN '07' ELSE '04' END;
Key Notes
- This query updates every row in the table: rows where
areamatches any of the four values getareatype = '07', all others getareatype = '04'—which aligns perfectly with your requirement. - I removed unnecessary parentheses around the
CASEexpression andWHENcondition to clean up the code, but those wouldn't have caused errors on their own. - Since
areatypeis achar(2)andareaischar(6), the string values ('07', '04', and the area codes) are properly sized for their respective columns.
内容的提问来源于stack exchange,提问作者Calflamesfann
相关产品推荐
相关产品推荐

