sql server conditional update

Posted on 2009-02-20
Last Modified: 2012-05-06
Need a sql statement that will do the following pseudocode

if field_1 = n1 then set field_2 = n2
if field_1 = o1 then set field_2 = o2
if field_1 = z1 then set field_2 = z2

please advise.
Question by:THz_
    LVL 25

    Accepted Solution

    Something like this -
    UPDATE <table>
    SET field_2 = CASE field 1 
    		WHEN n1 then n2
    		WHEN o1 then o2
    	        ELSE field_2

    Open in new window


    Author Comment

    Will check it out and let you know. Thanks.

    Featured Post

    IT, Stop Being Called Into Every Meeting

    Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

    Join & Write a Comment

    Use this article to create a batch file to backup a Microsoft SQL Server database to a Windows folder.  The folder can be on the local hard drive or on a network share.  This batch file will query the SQL server to get the current date & time and wi…
    In this article we will get to know that how can we recover deleted data if it happens accidently. We really can recover deleted rows if we know the time when data is deleted by using the transaction log.
    Illustrator's Shape Builder tool will let you combine shapes visually and interactively. This video shows the Mac version, but the tool works the same way in Windows. To follow along with this video, you can draw your own shapes or download the file…
    Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.

    733 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

    Need Help in Real-Time?

    Connect with top rated Experts

    23 Experts available now in Live!

    Get 1:1 Help Now