列名“USER_SOURCE”无效
我有一个存储过程,它在 xml @Data
输出参数中返回结果。
要在 xml 代码中分配数据,
SELECT @data= (
SELECT DISTINCT
CONVERT(varchar(2),u.USER_SOURCE ) + '~' +
CONVERT(varchar(20), u.[USER_ID]) + '-' +
CONVERT(varchar(10), u.DEALER_ID) as USER_DEALER_ID
FROM #users u FOR XML RAW('users'))
当我在 SQL Server Mgmt Studio 中执行该过程时,我可以看到结果正常。
该过程是从另一个过程调用的,并且该父过程在 SSRS 中使用。
在 SSRS 中我收到错误
数据集“DataSet1”的查询执行失败。列名无效 “用户源”。列名“USER_ID”无效。列名无效 “DEALER_ID”。
你能帮忙吗?
谢谢, 切坦
I have a stored procedure which is returning a result in an xml @Data
output parameter
To assign data in xml code is
SELECT @data= (
SELECT DISTINCT
CONVERT(varchar(2),u.USER_SOURCE ) + '~' +
CONVERT(varchar(20), u.[USER_ID]) + '-' +
CONVERT(varchar(10), u.DEALER_ID) as USER_DEALER_ID
FROM #users u FOR XML RAW('users'))
When I exec the procedure in SQL Server Mgmt Studio, I can see the result OK.
This procedure is been called from another procedure, and that parent procedure is used in SSRS.
In SSRS I am getting error
Query execution failed for dataset 'DataSet1'. Invalid column name
'USER_SOURCE'. Invalid column name 'USER_ID'. Invalid column name
'DEALER_ID'.
Could you please help?
Thanks,
Chetan
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这是一个脚本,我认为它重现了与您的问题相同的问题:
如您所见,这里有两个
#test
表,一个是在存储过程中创建的,另一个是在调用存储过程。它们具有不同的结构:一个具有名为value
的列,另一个具有名为value2
的列。如果运行该脚本,您将看到此错误:我目前无法向您指出相关文档文章,但对我来说,很明显,在执行 SP 之前立即进行了一些初步名称检查。在此阶段,存储过程中引用的列名与现有表中实际存在的列名之间的差异就会显现出来,这使得执行变得不可能。
如果将
value2
更改为value
,脚本将正常运行,并且输出中将有两个行集,其中一个带有'some text'
值,其他为空。当然,如果您删除与外部#test
表相关的所有部分,该脚本将起作用。因此,请检查调用您的过程的位置,看看当时是否存在任何其他
#users
表,如果存在,请根据您的情况修改问题。Here's a script which I think reproduces a problem identical to yours:
As you can see, there are two
#test
tables here, one is created in the stored procedure, the other one in the batch that invokes the stored procedure. They have different structures: one has a column namedvalue
, the other a column namedvalue2
. If you run the script, you'll see this error:I can't point you to a relevant documentation article at the moment, but to me it is evident enough that some preliminary name checking is taking place immediately before the execution of the SP. At that stage, a discrepancy between the column names referenced in the stored procedure and those actually present in the already existing table is revealed, which renders the execution impossible.
If you change
value2
tovalue
, the script will work without any problem, and there will be two row sets in the output, one with the'some text'
value, the other empty. And of course the script will work if you remove all parts related to the external#test
table.So, check the places where your procedure is called to see if any other
#users
table can be existing by that moment, and if so, amend the issue according to your situation.