-1

I want to read columns dynamically and concatenate values by using in SSIS. And it should generate a string of concatenate value which is delaminated by '|'. Nunber of columns will be not constant. Here is an example of what I am trying to do.

Input

Col1   Col2   Col3
123 ABC DEF

Output

Data
123|ABC|DEF

Could you please provide C# script for the same or any other solution.

Thanks, Nitin

Nitin
  • 7
  • 1

1 Answers1

0

here is the script to retrieve the SQL Statement, note you need to convert the non-character/string columns to string type, then only the concatenation will work

DECLARE @tblName NVARCHAR(250), @SQLstmt NVARCHAR(MAX)
SET @SQLstmt = ''
SET @tblName = <Replace with your table name>
SELECT @SQLstmt = @SQLstmt + '|' + COLUMN_NAME FROM INFORMATION_SCHEMA.COLUMNS WHERE TABLE_NAME = @tblName
SET @SQLstmt = SUBSTRING(@SQLstmt,2, LEN(@SQLstmt)-1)    

PRINT @SQLstmt

Senthil_Arun
  • 1,008
  • 9
  • 15