Click here to Skip to main content
15,910,471 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
How to set Variable value from exec string.

declare @Col nvarchar(30),@Sql nvarchar(500),@In decimal(18,2)
SQL
set @Sql=' select '+ (@col)+' FROM [INCENTIVE].[dbo].[Direct_Summary_Policies] where FinancialYear=''2013-2014'' and EmpCode=''E00532'' '


set @In=   (exec (@Sql)



it is wrong pls help me..
Posted
Updated 1-Jul-14 0:14am
v2

SQL
CREATE TABLE #TEST
(
TEST Decimal(18,0)
)


DECLARE @Sql nVARCHAR(500)

Declare @Col NVARCHAR(50)
SET @Col = 'TEST'



SET @Sql = '
DECLARE @Deci Decimal(18,0)
SELECT  @Deci  =  '+@Col +' From #test
SELECT @Deci
'

Exec (@sql)


I think this will help you
 
Share this answer
 
To execute a dynamically generated query, use sp_executesql.

http://www.mssqltips.com/sqlservertip/1160/execute-dynamic-sql-commands-in-sql-server/[^]
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900