Rahul Sharma

Rahul Sharma

  • NA
  • 289
  • 79.7k

Storing value in localvariable from dynamic sql in sql

Dec 10 2014 9:43 PM
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)