I have a small question
@CMD nvarchar (MAX)=''
SELECT @CMD +=N'
SELECT
COUNT(CASE WHEN RFRD.QueuTypeID=4
THEN RFRD.QueuTypeID
END) RequiredaQueue
,COUNT(CASE WHEN RFRD.QueuTypeID=3
THEN RFRD.QueuTypeID
END) BhinaQueue
,COUNT(CASE WHEN RFRD.QueuTypeID NOT IN (3,4)
,COUNT(DISTINCT RFRD.LeadDocumentID)AS Repeat,CONCAT('''+RF+''' ,''*'')A'
FROM #cte RF
p.s - The From is outside the dynamic.
Works fine here...
But when I add IF statement:
SELECT
COUNT(CASE WHEN RFRD.QueuTypeID=4
THEN RFRD.QueuTypeID
END) RequiredaQueue
,COUNT(CASE WHEN RFRD.QueuTypeID=3
THEN RFRD.QueuTypeID
END) BhinaQueue
,COUNT(CASE WHEN RFRD.QueuTypeID NOT IN (3,4)'
**IF @MyParam IS NOT NULL**
SET @CMD+='
,COUNT(DISTINCT RFRD.LeadDocumentID)AS Repeat,CONCAT('''+RF+''' ,''*'')A'
FROM #cte RF
The program doesn't understand what is the RF means.
it doesn't see the FROM #cte RF Anymore.
any body knows whats the problem with the IF statement??
thanks
theninif statement