'Run SQL Dynamic using column value [duplicate]

I am using dynamic SQL.

I inserted a select statement into one row from #example, I want to call that select statement and run it with dynamic SQL, my select stored has a variable call @NumOrder

create table #example(id int, description varchar(1000))

insert into #example(id, description)
values(1, 'select case when name=''Carlos'' then ''Pass'' else ''FAIL'' from server.dbo.person where number = @NumOrder')

declare @NumOrder int, @SQL nvarchar(max)

set @NumOrder=2621
set @SQL='description' 
--here is where I want to call my query and is failing 
--once I filled @NumOrder I want to display the results
exec(@SQL)

I want to run this dynamic SQL using a row stored into the temp table, I know that I can put the complete select statement into the @SQL and works but I want to know if there is a way to call the select statement in a row stored from a table. Is there a way to do this?



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source