Please start any new threads on our new
site at https://forums.sqlteam.com. We've got lots of great SQL Server
experts to answer whatever question you can come up with.
Author |
Topic |
skc40
Starting Member
34 Posts |
Posted - 2013-11-18 : 16:26:16
|
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=100SET @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
38200 Posts |
|
skc40
Starting Member
34 Posts |
Posted - 2013-11-18 : 16:40:00
|
TY, definitely helps |
|
|
|
|
|