Hi,
I seemed to me IsNull Evaluation within EXEC fails. Here's some more
detail of the problem.
-- goal: provide one parameter (of various value) to generate a
-- report
declare @col4 varchar(30)
select @col4 = null
-- pls note, the @col4 var is default to null but may likely
-- have a value
exec ('select col1, col2, col3, -- next dynamic col
' + @col4 + ',
col5, col6
count(*) as total
from FACT_TBL
where 1=1
-- THE FOLLOWING CONDITION EVALUATION FAILED
-- in the sense that if the parameter is not called query does
-- not return any result set, which is wrong
and COL4 = IsNull('''+@COL 4+''',COL4)
group by '+@COL4+', col5
')
I seemed to me IsNull Evaluation within EXEC fails. Here's some more
detail of the problem.
-- goal: provide one parameter (of various value) to generate a
-- report
declare @col4 varchar(30)
select @col4 = null
-- pls note, the @col4 var is default to null but may likely
-- have a value
exec ('select col1, col2, col3, -- next dynamic col
' + @col4 + ',
col5, col6
count(*) as total
from FACT_TBL
where 1=1
-- THE FOLLOWING CONDITION EVALUATION FAILED
-- in the sense that if the parameter is not called query does
-- not return any result set, which is wrong
and COL4 = IsNull('''+@COL 4+''',COL4)
group by '+@COL4+', col5
')
Comment