?
Solved

Case Statement

Posted on 2005-04-20
2
Medium Priority
?
246 Views
Last Modified: 2010-03-19
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%'
0
Comment
Question by:Pioneermfg
2 Comments
 
LVL 28

Accepted Solution

by:
rafrancisco earned 200 total points
ID: 13826622
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
 
LVL 3

Author Comment

by:Pioneermfg
ID: 13827012
It worked!!! Thanks
0

Featured Post

Granular recovery for Microsoft Exchange

With Veeam Explorer for Microsoft Exchange you can choose the Exchange Servers and restore points you’re interested in, and Veeam Explorer will present the contents of those mailbox stores for browsing, searching and exporting.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Ever wondered why sometimes your SQL Server is slow or unresponsive with connections spiking up but by the time you go in, all is well? The following article will show you how to install and configure a SQL job that will send you email alerts includ…
When trying to connect from SSMS v17.x to a SQL Server Integration Services 2016 instance or previous version, you get the error “Connecting to the Integration Services service on the computer failed with the following error: 'The specified service …
Via a live example, show how to set up a backup for SQL Server using a Maintenance Plan and how to schedule the job into SQL Server Agent.
Via a live example, show how to shrink a transaction log file down to a reasonable size.
Suggested Courses

850 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question