我已经写了下面提到的查询......
DECLARE @cols AS NVARCHAR(MAX),
@query AS NVARCHAR(MAX)
select @cols = STUFF((SELECT distinct ',' + QUOTENAME(Name)
from dbo.[WorkflowInstanceParameter]
FOR XML PATH(''), TYPE).value('.', 'NVARCHAR(MAX)'),1,1,'')
Go
set @query = 'SELECT ' + @cols + '
from
(
select wi.Id,wip.Name, wip.stringValue
from FROM [ESP2_DEV1].[dbo].[WorkflowInstanceParameter] wip,
[WorkflowParameterGroupInstance] wpgi, [ESP2_DEV1].[dbo].[WorkflowInstance] wi,
dbo.WorkflowDefinition wd
where wip.[WorkflowParameterGroupInstanceId] = wpgi.id
and wpgi.[WorkflowInstanceId] =wi.id and
wi.workflowDefinitionId=wd.id
) x
pivot
(
max(stringValue)
for Name in (' + @cols + ')
) p '
execute(@query)
但它失败并出现错误“关键字'FOR'附近的语法不正确”
谁能帮帮我????