I'm writing a query with the following structure:
IF (SELECT 8) = (SELECT 9)
INSERT INTO Quality_Report VALUES ('USBL', 'IM SL Current Time Period',(SELECT 8),(SELECT 9),'Match',GETDATE())
ELSE INSERT INTO Quality_Report VALUES ('USBL', 'IM SL Current Time Period',(SELECT 8),(SELECT 9),'Not Matched',GETDATE())
The SELECT "8" and "9" will be replaced with SELECT statements that return numeric value (like below).
SELECT
CASE when Sum(AVG_DLY_SLS_LST_35_DYS) =0 then 0 else
Sum(INVN_DOL) / Sum(AVG_DLY_SLS_LST_35_DYS)end as [IM DSO Current Time Period]
FROM [Mars_Bars_RAW].DBO.[LND_ITEMDETAILS]
LEFT JOIN [Mars_Bars_RAW].DBO.[LND_OpcoMaster] ON OpCo_NBR = Opco
WHERE FISC_WEEK = '37'
AND FY17_Market = 'Southeast'
When I replace both my SELECT statements with the actual queries, I get this error though: Msg 116, Level 16, State 1, Line 43 Only one expression can be specified in the select list when the subquery is not introduced with EXISTS.
Any reason I can't do this? Works fine with the dummy SELECT 8/9s.
Thanks,
Aucun commentaire:
Enregistrer un commentaire