Please see the SQL below:
declare @TableName VarChar(100)
declare @field1 varchar(100)
declare @field2 varchar(100)
set @TableName = 'Person.Person'
set @field1 = 'LastName'
set @field2 = 'FirstName'
Declare @SQL VarChar(1000) SELECT @SQL = 'SELECT ' + @field1 + ',' + @field2 + ' FROM '
SELECT @SQL = @SQL + @TableName
Exec ( @SQL)
The result set appears in two columns i.e. firstname and surname. Is it possible to concatenate the columns so the output appears like this?
Ian,McFearce
Jane,McAndrew
I have found a quote on this website: http://technet.microsoft.com/en-us/library/ms188001.aspx, which states: "concatenating two strings with the + operator, are not allowed". Therefore I suspect it is not possible. Is there a workaround.
@TableNameultimately come from? Why is your system designed so that people can choose any columns from any table?