Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6902725
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T07:50:02+00:00 2026-05-27T07:50:02+00:00

I am facing a complex situation of SQL queries. The task is to update

  • 0

I am facing a complex situation of SQL queries. The task is to update multiple rows, with multiple values and multiple conditions. Following is the data which I want to update;
Field to update: ‘sales’, condition fields: ‘campid’ and ‘date’:

if campid = 259 and date = 22/6/2011 then set sales = $200
else if campid = 259 and date = 21/6/2011 then set sales = $210
else if campid = 260 and date = 22/6/2011 then set sales = $140
else if campid = 260 and date = 21/6/2011 then set sales = $150

I want to update all these in one query.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T07:50:02+00:00Added an answer on May 27, 2026 at 7:50 am

    Try this:

    UPDATE your_table SET sales = 
    CASE 
        WHEN campid = 259 AND date = 22/6/2011 THEN 200
        WHEN campid = 259 AND date = 21/6/2011 THEN 210
        WHEN campid = 259 AND date = 22/6/2011 THEN 140
        WHEN campid = 259 AND date = 21/6/2011 THEN 150
        ELSE sales
    END
    

    Naturally I don’t know if date field is really DATE or DATETIME, so I left query showing what you can do, but maybe you have to fix dates comparison according to data type.
    If date field is DATE (as it should) you can write AND date = '2011-06-22' and so on.
    Note ELSE condition: it’s necessary to avoid records not falling inside other cases will be set to NULL.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm facing render issues in very complex WPF UI which contains, among other things,
I'm facing the following design issue: There will be several prepared SQL statements where
I am facing a problem creating a Json which is actually a complex one
I am facing a problem with .NET generics. The thing I want to do
I have a public facing website that has been receiving a number of SQL
I am facing an application designed to import huge amounts of data into a
I'm creating a complex website, which has quite a bit of code. So I
I'm facing the following problem and don't have an answer to it: We have
Im facing a problem where i want to schedule a certain java application to
Having WPF application with complex UI and want to write CodedUITest scripts for the

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.