1
こんにちは私の名前は本部MilindとCASEでMySQL UPDATEクエリ火災にしようとWHEN文であり、私は下に、このエラーを取得:キーワードが認識されません。 PHPで
24 errors were found during analysis.
Unrecognized keyword. (near "CASE" at position 27)
Unrecognized keyword. (near "WHEN" at position 32)
Unexpected token. (near "id" at position 37)
Unexpected token. (near "=" at position 39)
Unexpected token. (near "'2'" at position 40)
Unrecognized keyword. (near "THEN" at position 44)
Unexpected token. (near "'Y'" at position 49)
Unrecognized keyword. (near "ELSE" at position 53)
Unrecognized keyword. (near "status" at position 58)
Unrecognized keyword. (near "END" at position 65)
Unexpected token. (near "," at position 68)
Unrecognized keyword. (near "status" at position 71)
Unexpected token. (near "!=" at position 78)
Unrecognized keyword. (near "CASE" at position 81)
Unrecognized keyword. (near "WHEN" at position 86)
Unrecognized keyword. (near "status" at position 91)
Unexpected token. (near "=" at position 98)
Unexpected token. (near "'2'" at position 99)
Unrecognized keyword. (near "THEN" at position 103)
Unexpected token. (near "'N'" at position 108)
Unrecognized keyword. (near "ELSE" at position 112)
Unrecognized keyword. (near "status" at position 117)
Unrecognized keyword. (near "END" at position 124)
Unexpected token. (near "," at position 127)
と私のUPDETEクエリは以下の通りです:
UPDATE quotes SET status = CASE WHEN id='2' THEN 'Y' ELSE status END,
status = CASE WHEN id !='2' THEN 'N' ELSE status END,
WHERE id='2';
I status = Y insted of status = Nとstutus = N insted of status = Yのどこで更新したいか。
'!='はSQL構文ではありません。文字列をコンパイルするときには、たとえば次のようになります。 '' id 'like like' 2 'then ' – PhillipD
@PhillipD、'!= 'はANSI SQLの標準構文ではありませんが、ほぼすべてのSQL製品で認識されます。 https://stackoverflow.com/questions/723195/should-i-use-or-for-not-equal-in-t-sql/723426#723426 –
への私の答えを参照してください。@BillKarwin情報とリンクされていただきありがとうございます回答。 – PhillipD