根据以下场景,我如何从View实现此输出。
我只是以这种方式尝试
SELECT ',DynamicField'+ CAST(Seq AS NVARCHAR(10)) + ' as '
+ '['+ FieldName + ']' FROM dbo.Feilds
WHERE FieldName IS NOT null FOR XML PATH('') )
以上查询RETURNS
,DynamicField1 as [Name],DynamicField2 as [Fname],DynamicField3 as [Lname]
,DynamicField4 as [Gender],DynamicField5 as [Country]
SELECT id,Employeeid,DynamicField1 as [Name]
,DynamicField2 as [Fname],DynamicField3 as [Lname]
,DynamicField4 as [Gender],DynamicField5 as [Country] FROM TransactionDetails
答案 0 :(得分:0)
尝试这样,在[]
中包含列名SELECT ','+'['+'DynamicField'+ CAST(Seq AS NVARCHAR(10)) + ' as '
+ FieldName + ']' FROM dbo.Feilds
WHERE FieldName IS NOT null FOR XML PATH('')