SELECT
OrderId
,ShipDate
,SoldToId
,BillToId
...
FROM
OrderHeader
WHERE 1=1
AND OrderId = @OrderId
|
with MyData as (
SELECT
OrderId
,HasData = 1
,ShipDate
,SoldToId
,BillToId
...
FROM
OrderHeader
WHERE 1=1
AND OrderId = @OrderId
)
SELECT * FROM MyData
UNION SELECT
OrderId = ''
,HasData = 0
,ShipDate = getdate()
,SoldToId = 0
,BillToId = 0
...
WHERE NOT EXISTS (SELECT 2 FROM MyData)
|