0

I am trying to create a sql statement like

set @sql = 'select @stage1 = count(MY_ID)
From VW_OPEN
where ' + @filter

and run it with

exec (@sql)

However this generates an error
Must declare the variable '@stage1'.

If I run statement
select @stage1 = count(MY_ID)
From VW_OPEN

the var @stage 1 is set. Also @sql and @filter are all defind as varchars.

TIA

1
Contributor
2
Replies
3
Views
9 Years
Discussion Span
Last Post by hamishrock
0

Changing the select line to
Select ' + @stage1 + ' = count(MY_ID)

runs without error but returns an incorrect null value?

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.