I have written the query mentioned below...
我写了下面提到的查询...
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)
but it is failing with error "Incorrect syntax near the keyword 'FOR'"
但它失败并出现错误“关键字'FOR'附近的语法不正确”
Can anyone help me this?????
任何人都可以帮我这个?????
2 个解决方案
#1
2
The keyword FROM is repeated in the set @query clause:
关键字FROM在set @query子句中重复:
select wi.Id,wip.Name, wip.stringValue
from FROM [ESP2_DEV1].[dbo].[WorkflowInstanceParameter] wip
#2
3
This isn't really an answer for this post but if you google this error its one of the top hits.
这不是这篇文章的真正答案,但如果你谷歌这个错误,它的*点击之一。
I was running into this problem because I was trying to name a cursor with @
我遇到了这个问题因为我试图用@命名游标
declare @someName cursor for
this doesnt work.
这不起作用。
You need to do:
你需要这样做:
declare someName cursor for
instead.
代替。
I'm not clear if this is always the case as I've seen plenty of examples online which use @ and plenty which dont which is confusing. I'm new to sqlserver so not sure if there is something subtle going on here. However this definitely fixed the error in my case. This point seems to not be documented much online, however this other question documents it but was much harder to find on google for some reason!
我不清楚是否总是如此,因为我在网上看到很多使用@和大量的例子并不令人困惑。我是sqlserver的新手,所以不确定这里是否有微妙的东西。然而,这肯定修复了我的错误。这一点似乎没有在网上记录太多,但是这个其他问题记录了它,但由于某些原因在谷歌上找到更难!
Funny thing to force on names! I'm convertinig an oracle schema to sqlserver and had to add @ to variables everywhere but not these ones apparently! I guess the guys who did cursors missed that meeting or something!
有趣的事情迫使名字!我将一个oracle架构转换为sqlserver并且必须将@添加到各处的变量但显然不是这些变量!我猜那些做过游标的人都错过了那次会议!
#1
2
The keyword FROM is repeated in the set @query clause:
关键字FROM在set @query子句中重复:
select wi.Id,wip.Name, wip.stringValue
from FROM [ESP2_DEV1].[dbo].[WorkflowInstanceParameter] wip
#2
3
This isn't really an answer for this post but if you google this error its one of the top hits.
这不是这篇文章的真正答案,但如果你谷歌这个错误,它的*点击之一。
I was running into this problem because I was trying to name a cursor with @
我遇到了这个问题因为我试图用@命名游标
declare @someName cursor for
this doesnt work.
这不起作用。
You need to do:
你需要这样做:
declare someName cursor for
instead.
代替。
I'm not clear if this is always the case as I've seen plenty of examples online which use @ and plenty which dont which is confusing. I'm new to sqlserver so not sure if there is something subtle going on here. However this definitely fixed the error in my case. This point seems to not be documented much online, however this other question documents it but was much harder to find on google for some reason!
我不清楚是否总是如此,因为我在网上看到很多使用@和大量的例子并不令人困惑。我是sqlserver的新手,所以不确定这里是否有微妙的东西。然而,这肯定修复了我的错误。这一点似乎没有在网上记录太多,但是这个其他问题记录了它,但由于某些原因在谷歌上找到更难!
Funny thing to force on names! I'm convertinig an oracle schema to sqlserver and had to add @ to variables everywhere but not these ones apparently! I guess the guys who did cursors missed that meeting or something!
有趣的事情迫使名字!我将一个oracle架构转换为sqlserver并且必须将@添加到各处的变量但显然不是这些变量!我猜那些做过游标的人都错过了那次会议!