2
Answers

Storing value in localvariable from dynamic sql in sql

Rahul Sharma

Rahul Sharma

9y
628
1
declare @EndDate varchar(50)
set @EndDate = '2014-11-17'
declare @monthend varchar(50)
set @monthend = 'select' + ' '+ 'MONTH('+ ''''+@EndDate+''''+')'
declare @flag int
set @flag = exec @monthend
select @flag
if @flag ='11'
 
I want to store result comes from dynamic query @monthend into variable @flag.and use the value @flag in the if else condition.
Answers (2)