Deepak M Deepak M - 7 months ago 46
SQL Question

MS SQL: How union works inside if exists condition?

Can anyone explain how union works inside if exists? My code is below.

if exists(select top 1 ShoppingCartNo from tbSupplierLineItem
where BidSummaryDueDate>CONVERT(date,getdate()) and ShoppingCartNo=@SC
select top 1 ShoppingCartNo from Protrac_Archieve.dbo.tbSupplierLineItem
where BidSummaryDueDate>CONVERT(date,getdate()) and ShoppingCartNo=@SC)
SQL statements

Answer Source

It first combines the result sets of two select queries inside if exists statement and then checks for the existence of any record from those queries.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download