SQL Server Forums
Profile | Register | Active Topics | Members | Search | Forum FAQ
 
Register Now and get your question answered!
Username:
Password:
Save Password
Forgot your Password?

 All Forums
 SQL Server 2008 Forums
 Transact-SQL (2008)
 Trap output generated to a variable
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

skc40
Starting Member

29 Posts

Posted - 11/18/2013 :  16:26:16  Show Profile  Reply with Quote
Hi All,
The @FieldName_Varchar variable is dynamic, but for testing purpose declare variable as below.

How can I generate and trap value generated from @SQL statement below to @Output_Data without using temp table/table variable?

EMPLOYEEID varchar(100) is 20099 for Emp_ID below.

I want to generate @Output_Data=20099!!

DECLARE @FIELDNAME VARCHAR(200),
@EMP_ID INT,
@SQL NVARCHAR(500),@Output_Data VARCHAR(100)

SET @EMP_ID=100

SET @FIELDNAME='EMPLOYEE_INFO.EMPLOYEEID'

SET @SQL='SELECT '
SET @SQL= @SQL + @FieldName
SET @SQL= @SQL + ' FROM EMPLOYEE_INFO WHERE EMPLOYEE_INFO.EMPLOYEEID=' + CAST(@EMP_ID AS VARCHAR)

PRINT @SQL
--EXECUTE sp_executesql @SQL

tkizer
Almighty SQL Goddess

USA
36601 Posts

Posted - 11/18/2013 :  16:35:26  Show Profile  Visit tkizer's Homepage  Reply with Quote
See example C for the OUTPUT option of sp_executesql: http://technet.microsoft.com/en-us/library/ms188001.aspx

Tara Kizer
SQL Server MVP since 2007
http://weblogs.sqlteam.com/tarad/
Go to Top of Page

skc40
Starting Member

29 Posts

Posted - 11/18/2013 :  16:40:00  Show Profile  Reply with Quote
TY, definitely helps
Go to Top of Page
  Previous Topic Topic Next Topic  
 New Topic  Reply to Topic
 Printer Friendly
Jump To:
SQL Server Forums © 2000-2009 SQLTeam Publishing, LLC Go To Top Of Page
This page was generated in 0.06 seconds. Powered By: Snitz Forums 2000