1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
|
DECLARE @cpt int,@champ int
DECLARE @SQLString varchar(max)
SET @SQLString = 'case '
SET @champ=1
SET @cpt=(select count(*) FROM [1-transfert].INFORMATION_SCHEMA.COLUMNS WHERE TABLE_NAME='tmp_bla_verbatim')
PRINT 'Nb colonne : ' + cast(@cpt as varchar)
WHILE @champ<=@cpt
BEGIN
SET @SQLString = @SQLString + (SELECT 'when [' + COLUMN_NAME + ']=''1'' and COLUMN_NAME = ''' + replace(COLUMN_NAME,'''','''''') + ''' then ''' + replace(COLUMN_NAME,'''','''''') + ''''
FROM [1-transfert].INFORMATION_SCHEMA.COLUMNS
WHERE TABLE_NAME='tmp_bla_verbatim' and ORDINAL_POSITION = @champ)
PRINT cast(@champ as varchar) + ' ' + @SQLString
SET @champ=@champ + 1
END |
Partager