declare @result nvarchar(500) declare @sql nvarchar(500) declare @tableName nvarchar(30) declare @colText nvarchar(30) declare @colKey nvarchar(30) declare @pid nvarchar(10) set @result=''
set @tableName='purchase_po_in_details' set @colText='product_name' set @colKey='po_in_id' set @pid=6 set @result=''; set @sql=' select @result += '+@colText+'+'';'' from '+@tableName+' where '+ @colKey+'='+@pid+' ';
exec sp_executesql @sql,N' @result nvarchar(500) output',@result output select @result