Forum Discussion

nrajeshkumars's avatar
nrajeshkumars
Copper Contributor
Feb 12, 2024

SQL query to retrieve Expected result

Hi ,

From the below table and insert value script i need to derive the expected result value. 

Required help in this .

 

CREATE TABLE #data(MainID int NOT NULL,
Component varchar(10) NOT NULL,
Value varchar(10) NOT NULL,
Seqno int
)
go

INSERT #data (MainID, Component, Value,Seqno)
VALUES(1, 'ALPHA', 'Y',1),
(1, 'BETA', 'N',2),


(1, 'GAMMA', 'N',3),
(1, 'DELTA', 'Y',4),
(1, 'EPSILON', 'Y',5),
(2, 'London', 'N',1),
(2, 'New York', 'Y',2),
(2, 'Mumbai', 'N',3)
go

 

Required result:

MainIDComponentValueSeqnoExpecting result
1ALPHAY11
1BETAN22
1GAMMAN32
1DELTAY43
1EPSILONY53
2LondonN11
2New YorkY22
2MumbaiN33

1 Reply

  • olafhelper's avatar
    olafhelper
    Bronze Contributor
    And what's the logic for the "expected result"; just by having a look at I don't get it?