mardi 11 septembre 2018

IF Condition Perform Query, Else Perform Other Query Base on Count to Execute

I want select Tow types of query using If and else condition...

CASE when 
(select Count(*) from dcdetail d 
LEFT JOIN finalbilldetail f ON d.itemid = f.itemid AND ISNULL(d.itemcolorid,'') = ISNULL(f.itemcolorid,'')
where f.itemid IS NULL and d.id = 12) > 0        

    THEN
SELECT dm.ID ,dm.Status ,dm.EntryDate ,dm.EntryTime ,ci.cusid ,ci.cusname ,ci.cuscontact
FROM DcMaster dm
left join RegCustomerInfo ci on dm.customerID = ci.CusID
where dm.customerid = 8

    ELSE 
<Other Query>
END

Aucun commentaire:

Enregistrer un commentaire