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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T07:25:47+00:00 2026-05-26T07:25:47+00:00

I have a tableA: (ID int, matchPID char,PID char, set int, num char, QID

  • 0

I have a tableA: (ID int, matchPID char,PID char, set int, num char, QID char, QStatus char)

ID matchPID   PID    set  num   QID  QStatus 
1  00001230   xx123   1   234  
2  00001229   xx234   1   214
3  00000054   xx654   1   NULL
4  00012000   xx125   2   
5  00A53214   xx321   2   
6  00000100   xx213   2

matchPID is always (00-xxxxxx) x can be char or int.

now I have to populate OID just one value for each set according to [num].

  1. If for any set, there exists any value in [num], then populate OID with PID where exists [num] for same set and populate Qstatus = ‘fail’ in rest.

so OID can be populated in id 1 or 2. (any1), then check lowest matchPID and populate here. so in this case (set1) expected result is :

ID matchPID   PID    set  num   QID       QStatus 

1  00001230   xx123   1   234   NULL       FAIL
2  00001229   xx234   1   214   xx234      NULL
3  00000054   xx654   1   NULL  NULL       FAIL
  1. if for any set there isnt any [num] found, then pick lowest matchPID and populate QID with PID and fail the rest.

notice that matchPID starts with 00 and then it can be 0>1>2>..>A>B>C>….
so expected result for set2 is :

ID matchPID   PID    set  num   QID       QStatus

4  00012000   xx125   2   NULL  NULL      FAIL
5  00A53214   xx321   2   NULL  NULL      FAIL
6  00000100   xx213   2   NULL  xx213     NULL

Thanks

  • 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-26T07:25:48+00:00Added an answer on May 26, 2026 at 7:25 am

    Did you want something like this?:

    ;WITH setInfo AS (
    SELECT [SET], 
        CASE WHEN EXISTS (SELECT 1 FROM tableA b 
                                    WHERE b.[set]=a.[set] AND num IS NOT NULL) 
                                    THEN 1 ELSE 0 END AS HasNum,
        MIN(matchPID) AS MinMatchPID
    FROM tableA a
    GROUP BY [SET]
    )
    UPDATE a SET
    QID = CASE WHEN s.HasNum = 0 AND a.matchPID = s.MinMatchPID THEN a.PID
               WHEN s.HasNum = 0 AND a.matchPID != s.MinMatchPID THEN NULL
               WHEN s.HasNum = 1 AND a.matchPID = (SELECT min(matchpid) FROM tableA b
                                         WHERE b.[set] = a.[set]
                                         AND b.num is not null
                                          ) 
                                         THEN a.PID
               ELSE NULL
               END,
    QStatus = CASE WHEN s.HasNum = 0 AND a.matchPID = s.MinMatchPID THEN NULL
               WHEN s.HasNum = 0 AND a.matchPID != s.MinMatchPID THEN 'FAIL'
               WHEN s.HasNum = 1 AND a.matchPID = (SELECT min(matchpid) FROM tableA b
                                         WHERE b.[set] = a.[set]
                                         AND b.num is not null
                                          ) 
                                         THEN a.PID
               ELSE 'FAIL'
               END
    FROM tableA a
    JOIN setInfo s ON s.[set] = a.[set]
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a tableA (ID int, Match varchar, code char, status = char) ID
I have two tables. TableA ( ID int, Match1 char, Match2 char, status char
I have this table (TableA): ( [FieldA] [int] NOT NULL, [FieldB] [int] NOT NULL,
I have the following tables: create table TableA ( Id int primary key identity,
I have two tables, TableA and TableB: CREATE TABLE `TableA` ( `shared_id` int(10) unsigned
I have the following linq to sql: int someNumber = (from a in TableA.col1
I have 2 tables: TableA ------ TableAID INT IDENTITY Primary Key TableBID INT NULL
I have two tables: TableA ( ID [int, pk], Name [string]) and TableB (ID
I have SQL Server tables as follows: create table TableA ( id int primary
I have a table(say TableA) with the following schema A(int) B(int) D (varchar) C(date)

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.