SELECT
Concat(
IIf(Id IS NULL, Null, Concat('Id: ' , [Id] , '\n') ) ,
IIf(StandardClientId IS NULL, Null,
Concat('StandardClientId: ' , [StandardClientId] , '\n') ) ,
IIf(ClientName IS NULL, Null,
Concat('ClientName: ' , [ClientName] , '\n') )
) AS ReportLine
FROM dbo.DataDecoded;
我使用的是Microsoft SQL Server 2014 Standard。
由于
答案 0 :(得分:1)
最简单的方法是编写一个查询,为您编写语句的烦人部分:
SELECT ORDINAL_POSITION,
COLUMN_NAME,
CONCAT('IIF(',COLUMN_NAME,' IS NULL, NULL, CONCAT(''', COLUMN_NAME, ''', '': '',', QUOTENAME(COLUMN_NAME), ', ''\n'')), ')
FROM INFORMATION_SCHEMA.COLUMNS
WHERE TABLE_SCHEMA = 'dbo'
AND TABLE_NAME = 'DataDecoded'
ORDER BY ORDINAL_POSITION;
你可以更进一步,让整个事物充满活力,但这可能是浪费时间。