Case Statement

I need to find if a field has a value of "key" then change that value to "1234567890'. Here is the statement

USE DB1
DECLARE @CHK CHAR(10)
SET @CHK = '1234567890'
SELECT DOCTYPE, VENDORID, DOCDATE, DOCNUMBR, DOCAMNT, CHEKBKID, VOIDED,
CASE WHEN CHEKBKID = 'KEY' THEN CHEKBKID = @CHK
FROM PM30200

WHERE DOCTYPE =6 AND DOCDATE = '4/19/2005' AND DOCNUMBR LIKE '0124%'
LVL 3
PioneermfgAsked:
Who is Participating?
 
rafranciscoCommented:
Try this:

SELECT DOCTYPE, VENDORID, DOCDATE, DOCNUMBR, DOCAMNT, CHEKBKID, VOIDED,
CASE WHEN CHEKBKID = 'KEY' THEN '1234567890' ELSE CHEKBKID END AS CHEKBKID
FROM PM30200
WHERE DOCTYPE =6 AND DOCDATE = '4/19/2005' AND DOCNUMBR LIKE '0124%'
0
 
PioneermfgAuthor Commented:
It worked!!! Thanks
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.