Code declare@CustomerIDnvarchar(4000) declare@startTimedatetime declare@endTimedatetime set@startTime=\'2008-09-01\' set@endTime=\'2008-10-01\' set@CustomerID= N\'11015001,11015002,11015003,11015007,11015093,11015099,11015100\' declare@strsqlnvarchar(3000) set@strsql=\'select
temp.ProductName as AssetName,
temp.TransactionTime,
case when temp.PurchaseType >1 then \'\'Download to Rent\'\'
else \'\'Download to Own\'\'
end as PurchaseType,
temp.Provider,
case when Temp.ShopCartID=0 then \'\'Archos\'\'
else \'\'Portal\'\'
end as \'\'Sold VIA\'\',
temp.CustomerID,
case when temp.CustomerID in(\'+@CustomerID+\') then \'\'Tester\'\'
else \'\'Live\'\'
end \'\'AccountType\'\'
from
(select tblbilling.TransactionTime,
tblbilling.CustomerID,
tblProduct.ProductName,
tblProduct.PurchaseType,
tblAsset.Archos,
tblOrder.ShopCartID,
tblAssetMetadata.Provider
from tblbilling inner join tblProduct on tblbilling.ProductPK = tblProduct.ProductPK
inner join tblOrder on tblBilling.OrderID = tblOrder.OrderID
inner join tblAsset on tblProduct.StandardAssetPks =tblAsset.AssetPk
inner join tblAssetMetadata on tblAsset.AssetPk = tblAssetMetadata.AssetPK
where tblbilling.Status in(301,302) and (tblbilling.TransactionTime between \'\'\'+convert(nvarchar(30),@startTime,120)+\'\'\' and \'\'\'+convert(nvarchar(30),@endTime,120) +\'\'\')) as temp\' exec(@strsql)