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 7418563
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T07:54:37+00:00 2026-05-29T07:54:37+00:00

How can I update multiple records in a database using one Update statement where

  • 0

How can I update multiple records in a database using one Update statement where the cases are different.

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

This fails and should look like:

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

The difference being that the Else comes right at the end.

But it sets refundNumber on ALL records to 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.

I’ve not tested it, but I believe the VB logic I’d need would be:

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

How could I translate this to an SQL CASE string?

  • 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-29T07:54:38+00:00Added an answer on May 29, 2026 at 7:54 am

    If you don’t want to update records where the InvNo is not ‘1’ and the itemNo is not ‘250’ or ‘7095’ why not have a where clause limiting the set to this criteria? Then all you need to do concatenate refund number and 88 using a case expression, but you don’t even need this you could use:

    UPDATE yourtable
    SET refundNumber = ISNULL(CONCAT(NULLIF(refundNumber, ''), ', 88'), '88')
    WHERE InvNo = '1'
    AND itemNo in ('250', '7095')
    

    Or use a nested case expression?

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

Sidebar

Related Questions

How can i update multiple records in a single statement like this with SQL?:
i'm wondering how am i suppose to update my database data of different records
How can I update multiple values in MySQL? This didn't work: UPDATE test SET
I see that EF can update a model based on an existing database schema.
I'm generating ICalendar (.ics) files. Using the UID and SEQUENCE fields I can update
I want to iterate over records in the database and update them. However since
I have a form that enables a user to update multiple alert rules records
Can someone provide a good example of multiple UpdatePanels being updated by a singe
How can update a input hidden inside an UpdatePanel on an AsyncPostBack? The user
I know I can update a single record like this - but then how

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.