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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T11:27:58+00:00 2026-06-18T11:27:58+00:00

MS SQL 2008 in use and stored procedure is needed. So in my table

  • 0

MS SQL 2008 in use and stored procedure is needed.

So in my table i have certain rows where IsDouble value will be 2.
Now i need to update IsDouble from 2 to 1 for each line from the first select if a count of string (concatenated from 4 columns) is greater than 1 and if the count of the string is 1 to 0

So far i have this but it’s most likely incorrect:

select * from TestInvoiceData where Isdouble='2';
update TestInvoiceData
set testinvoicedata.Isdouble=
case 
    when  
    (
        select COUNT (InvoiceDate+InvoiceNumber+VendorCode+Invoicetype) 
        from      TestInvoiceData
     ) >1 then 1
     else 0
end;

EDIT

Here’s the sample data (invoicetype,invoicenumber,invoicedate,vendorcode):

INVO    322760-262  2012-05-10  0000081964  2
INVO    322760-262  2012-05-10  0000081964  0
INVO    322756-262  2012-05-10  0000081964  2
INVO    7011200072  2012-05-10  0000046172  0
INVO    7011200071  2012-05-10  0000046172  0
INVO    7011200070  2012-05-10  0000046172  0
INVO    7011200069  2012-05-10  0000046172  0
INVO    7011200068  2012-05-10  0000046172  0
INVO    12106563    2012-04-24  0000010171  0
INVO    06649       2012-04-24  0000067987  0

and based on this example the first row should be after update 1 and the third one 0

  • 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-06-18T11:27:59+00:00Added an answer on June 18, 2026 at 11:27 am

    Query:

    SQLFIDDLEEXAmple

    UPDATE TestInvoiceData
    SET Isdouble = (
    SELECT   CASE WHEN count(*)>1 THEN 1
             ELSE 0 END AS cnt
    FROM TestInvoiceData t1
      WHERE t1.invoicetype =TestInvoiceData.invoicetype 
      AND   t1.invoicenumber = TestInvoiceData.invoicenumber
      AND   t1.invoicedate = TestInvoiceData.invoicedate
      AND   t1.vendorcode = TestInvoiceData.vendorcode
    GROUP BY t1.invoicetype,
             t1.invoicenumber,
             t1.invoicedate,
             t1.vendorcode)
    WHERE Isdouble = '2'
    

    Result:

    | INVOICETYPE | INVOICENUMBER |                  INVOICEDATE | VENDORCODE | ISDOUBLE |
    --------------------------------------------------------------------------------------
    |        INVO |    322760-262 |   May, 10 2012 00:00:00+0000 |      81964 |        1 |
    |        INVO |    322760-262 |   May, 10 2012 00:00:00+0000 |      81964 |        0 |
    |        INVO |    322756-262 |   May, 10 2012 00:00:00+0000 |      81964 |        0 |
    |        INVO |    7011200072 |   May, 10 2012 00:00:00+0000 |      46172 |        0 |
    |        INVO |    7011200071 |   May, 10 2012 00:00:00+0000 |      46172 |        0 |
    |        INVO |    7011200070 |   May, 10 2012 00:00:00+0000 |      46172 |        0 |
    |        INVO |    7011200069 |   May, 10 2012 00:00:00+0000 |      46172 |        0 |
    |        INVO |    7011200068 |   May, 10 2012 00:00:00+0000 |      46172 |        0 |
    |        INVO |      12106563 | April, 24 2012 00:00:00+0000 |      10171 |        0 |
    |        INVO |         06649 | April, 24 2012 00:00:00+0000 |      67987 |        0 |
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a stored procedure written in T-SQL and want to use a table
I use MS SQL 2008 R2, I need create a Table with a CHECK
I use SQL Server 2008 R2 and have a table that I want no
I use SQL Server 2008 and have a table with 5 char typed columns.
I use the following stored procedure from my SQL Server 2008 database to return
I have a stored procedure in SQL Server 2008 that I want to store
I have a stored procedure in SQL Server 2008 that consists of multple select
I have a Stored Procedure(SP) in MS SQL 2008 R2 I'm building that requires
I am trying to write a stored procedure in sql server 2008,I need to
I have a weird requirement which I need to use inside my Stored Procedure

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.