Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

muliple reoceds in a Case statement 2

Status
Not open for further replies.

siituser

Programmer
Sep 30, 2002
67
CA
I've got a fairly simple Case statement:

Select (Case
when(Select distinct TSR.QP
From TSR
where TSR.DateStart between Date1 and Date2 and TSR.isActive =1) = 0 then 0

when(Select distinct TimeSheetRaw.QuickPay
From TSR
where TSR.DateStart between Date1 and Date2 and TSR.isActive =1) = 1 then 1
end ) as QP

It has worked well up to this point - we have now found an instance where the inner Select statement can have 2 distinct records.

Is there a way to use the 'record count' of the select statment in a WHEN? logic: if the recordcount of the select > 1 then 1

or how else can I handle multiple recordsets in a case statement
 
How about
WHERE RecordID IN (SELECT RecordID, COUNT(*) FROM Table
GROUP BY RecordID HAVING COUNT > 1)

or

WHERE RecordID IN (SELECT MAX(RecordID))

REgards ACO
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top