You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

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

  1. Unclosed Quotation Mark: The last value in your IN list ('000999鈥�') has a mangled character instead of a proper closing single quote. This is the primary cause of the Unclosed quotation mark error.
  2. Parser Confusion: Because of the unclosed quote, the SQL parser got confused and threw a secondary error about the WHERE keyword (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 area matches any of the four values get areatype = '07', all others get areatype = '04'—which aligns perfectly with your requirement.
  • I removed unnecessary parentheses around the CASE expression and WHEN condition to clean up the code, but those wouldn't have caused errors on their own.
  • Since areatype is a char(2) and area is char(6), the string values ('07', '04', and the area codes) are properly sized for their respective columns.

内容的提问来源于stack exchange,提问作者Calflamesfann

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.27 06:43:40