declare @var varchar(max),@course varchar(max)
set @var='ABC'
set @Query=''
set @Query='
select @course=PARAM from TABLE where PARAM='''+@var+''''
print @Query
exec (@Query)
Since the above query returns an error as
Must declare the scalar variable "@course"
The query here is the alternative I am following right now to make that query successful.
declare @var varchar(max),@course varchar(max),@Query varchar(max)
Create table #temp(param1 varchar(max))
set @var='ABC'
set @Query=''
set @Query='insert #temp(param1)
select PARAM from TABLE where PARAM='''+@var+''''
print @Query
exec (@Query)
select @course=param1 from #temp
drop table #temp
Is there any other better alternative to this other than the solution I have mentioned above?