【发布时间】:2018-05-21 20:35:59
【问题描述】:
目前我有以下问题
我创建了一个 Strred 过程,它根据在 SSRS 中设计的报告中接收到的参数执行动态 SQL。
这是程序:
alter PROCEDURE TablaDinamica @initdate datetime,
@finaldate datetime, @pin varchar(30), @RID varchar(10),
@PinState varchar(15), @charger varchar(50), @Document varchar(20)
AS
BEGIN
Declare @Where1 nvarchar(max) = ''
Declare @Where2 nvarchar(max) = ''
Declare @Where3 nvarchar(max) = ''
Declare @Select nvarchar(max)
Declare @FROM nvarchar(max)
if(@initdate IS NOT NULL and @finaldate IS NOT NULL)
BEGIN
SET @Where1 = 'a.generationdate between ''' + @initdate + ''' and
'''+ @finaldate + ''''
if(@pin is not null or @pinstate is not null or @NombreRecaudador is not null)
SET @Where1 = @Where1+' and '
END
if(@pin is not null)
BEGIN
SET @Where2= 'pin='''+@pin+''''
if(@pinstate is not null or @charger is not null)
SET @Where2 = @Where2+' and '
END
if(@pinstate IS NOT NULL)
BEGIN
SET @Where3 = 'e.Nombre ='''+ @EstadoPin + ''''
if(@charger is not null)
SET @Where3 = @Where3+' and '
END
SET @Select= 'SELECT a.OpRCId,
a.Id,
f.OpClientId,
f.names,
f.lastnames,
f.Birthdate
SET @FROM = 'FROM
a inner join b ON a.OpId =
b.OpId
INNER JOIN c ON b.AdId = c.AdId
INNER JOIN d ON c.AdId = d.AdId
INNER JOIN e ON a.CId = e.CId
INNER JOIN f ON b.OpId = f.OpId
INNER JOIN g ON a.AdRId = g.AdRId
INNER JOIN s ON c.AdSId = s.AdSId
WHERE f.document = '''+@Document+''''
EXECUTE(@SELECT+@FROM+@Where1+@where2+@Where3)
END
执行时,它在 SSMS 上完美运行,但在 SSRS 上,这是错误
The multi-part identifier "a.OpRCId" could not be bound.
没有其他迹象表明有任何问题
感谢您能给我的任何帮助!
问候!
注意:根据请求,这是一个
的架构CREATE TABLE [dbo].[a](
[OpId] [int] IDENTITY(1,1) NOT NULL,
[OpCId] [int] NOT NULL,
[CnEId] [int] NOT NULL,
[OpLId] [int] NOT NULL,
[AdId] [int] NOT NULL,
[CnEId] [int] NOT NULL,
[ANI] [numeric](18, 3) NOT NULL,
[generationdate] [datetime] NOT NULL,
[paymentdate] [datetime] NULL,
[Pin] [varchar](30) NOT NULL,
[Recovery] [numeric](18, 3) NOT NULL,
[References] [varchar](50) NOT NULL,
[Company] [numeric](18, 3) NOT NULL,
[Total] [numeric](18, 3) NOT NULL,
[Value] [numeric](18, 3) NOT NULL,
【问题讨论】:
-
对我来说,您似乎在 f.Birthdate 和空格之后缺少一些引号,并删除了 f.birthdate 和 from 之间的额外逗号
-
你能把
schema的a发帖吗 -
您好,@HolmesIV 谢谢,我已经在问题中进行了调整
-
@maSTAShuFu 我已经添加了a的架构
-
@LightningSnake ...查看错误你能从你的架构中找到相同的列吗?
标签: sql-server stored-procedures reporting-services