ケースが異なる1つのUpdateステートメントを使用してデータベース内の複数のレコードを更新するにはどうすればよいですか。
refundNumber = CASE _
WHEN salesRecords.invNo='1' AND itemNo='250' AND length(refundNumber) > 1 THEN _
concat(refundNumber, ', 88' ) Else '88' _
WHEN salesRecords.invNo='1' AND itemNo='7095' AND length(refundNumber) > 1 THEN _
concat(refundNumber, ', 88' ) Else '88' _
END
これは失敗し、次のようになります。
refundNumber = CASE _
WHEN invNo='1' AND itemNo='250' AND length(refundNumber) > 1 THEN _
concat(refundNumber, ', 88' ) _
WHEN invNo='1' AND itemNo='7095' AND length(refundNumber) > 1 THEN _
concat(refundNumber, ', 88' ) Else '88' _
END
違いは、Elseが最後に来るということです。
しかし、すべてのレコードの refundNumber
を88に設定します。
What I am trying to do is add a value to a field named refundNumber
to those items where the invNo = 'currentInvoiceNumber'
AND itemNo = 'itemNumber'
BUT, since refundNumber
is a text field which is meant to contain a comma separated list, I am trying to determine whether this field is empty or not, if it is, just enter the number, if it isn't, append the number preceded by a comma to the existing field content. Hence the length(refundNumber) > 1 THEN concat(refundNumber, ', 88' )
bit.
私はそれをテストしていないが、私はVB論理私が必要と思います:
IF invNo='1' And itemNo='250' THEN
IF length(refundNumber) > 1 THEN
concat(refundNumber, ', 88' )
ELSE
'88'
END IF
ELSE IF invNo='1' And itemNo='7095' THEN
IF length(refundNumber) > 1 THEN
concat(refundNumber, ', 88' )
ELSE
'88'
END IF
Else
refundNumber '- leave the field value as is because it does not comply with any of the above conditions
END IF
これを SQL CASE
文字列に変換するにはどうすればよいですか?