美好的一天,我正在尝试在SSRS中创建数据集,不幸的是我需要创建一个临时表来创建我的报告。我的代码如下
merge
我如何将此代码移至SSRS?
我试过了create table #Tax_Admin (AWD varchar (255), Name varchar(255))
insert into #Tax_Admin
values ('MDSTM','Agent 1'),
('MDSAK','Agent 2'),
('ITDPM','Agent 3'),
('MASEL','Agent 4'),
('ITDEK','Agent 5'),
('ITDFM','Agent 6');
with #transactions_workingwith
as
(
SELECT distinct
[TRANSACTION_ID]
FROM [mmcenvsqlprd01].[MOMDWL1].[ibrststdatEQ].[MOVEMENT_DATA] A
where
(a.TO_QUEUE like '%FINTAX%'
OR a.TO_QUEUE like '%TAXQ%'
OR a.TO_QUEUE like '%TAXCERT%')
and a.TO_STATUS_DATE >= '2017-06-01')
, User_Movements as
(
Select
a.TRANSACTION_ID
,a.POLICY_NUMBER
,a.USER_ID
,a.BILLING_CYCLE_ID
,a.TRANSACTION_TYPE
,a.FROM_STATUS
,a.TO_STATUS
,a.TO_STATUS_DATE
,a.TO_QUEUE
, ROW_NUMBER() over (Partition by a.TRANSACTION_ID order by a.TO_STATUS_DATE) as User_Movement_Nr
,case when (a.TO_QUEUE like '%FINTAX%'
OR a.TO_QUEUE like '%TAXQ%'
OR a.TO_QUEUE like '%TAXCERT%') then 'Tax Queue' else 'Other Queue' end as Queue_Taype
FROM [mmcenvsqlprd01].[MOMDWL1].[ibrststdatEQ].[MOVEMENT_DATA] A
inner join #transactions_workingwith b on a.TRANSACTION_ID Collate SQL_Latin1_General_CP1_CI_AS = b.TRANSACTION_ID Collate SQL_Latin1_General_CP1_CI_AS
where
a.TO_STATUS_DATE >= '2017-06-01')
Select distinct
a.TRANSACTION_ID
,a.POLICY_NUMBER
,convert(varchar,a.TO_STATUS_DATE,112) + isnull(c.EMPLOYEE_NR,d.EMPLOYEE_NR) as EmployeeKey ---Why do we need this empoyee key?
,a.USER_ID
,isnull(c.EMPLOYEE_NR,d.EMPLOYEE_NR) as Emplyee_Nr
,f.[BusinessArea]
,a.TRANSACTION_TYPE
,a.FROM_STATUS
,a.TO_STATUS
,b.TO_STATUS as Next_Status
,b.USER_ID as Next_Status_User
,isnull(e.Name,'Other') as Tax_Admin_Name
,case when b.TO_STATUS like '%FAIL%' THEN 1 ELSE 0 END AS Is_Fail
,case when b.TO_STATUS like '%INFO%' THEN 1 ELSE 0 END AS Is_Info
,case when b.TO_STATUS like '%TRAIN%' THEN 1 ELSE 0 END AS Is_Train
,
case when b.TO_STATUS like '%FAIL%' THEN 1 ELSE 0 END
+ case when b.TO_STATUS like '%INFO%' THEN 1 ELSE 0 END
+ case when b.TO_STATUS like '%TRAIN%' THEN 1 ELSE 0 END as Returned
,a.TO_STATUS_DATE
,a.TO_QUEUE
,a.User_Movement_Nr
,a.BILLING_CYCLE_ID
,1 as Movement
from User_Movements a
inner join User_Movements b
on a.TRANSACTION_ID = b.TRANSACTION_ID and a.User_Movement_Nr + 1 = b.User_Movement_Nr
left JOIN [mmcenvsqlprd01].momdwl1.ibrststcnfEQ.IBRS_USER_INFO c
on a.USER_ID Collate SQL_Latin1_General_CP1_CI_AS = c.USER_ID Collate SQL_Latin1_General_CP1_CI_AS
left JOIN [mmcenvsqlprd01].momdwl1.ibrststcnfWealth.IBRS_USER_INFO d
on a.USER_ID Collate SQL_Latin1_General_CP1_CI_AS = d.USER_ID Collate SQL_Latin1_General_CP1_CI_AS
left join #Tax_Admin e on b.USER_ID Collate SQL_Latin1_General_CP1_CI_AS = e.AWD Collate SQL_Latin1_General_CP1_CI_AS
inner join [mmcenvsqlbi01].[Master_Data].[Trans].[Employee_Snapshot] f
on convert(varchar,a.TO_STATUS_DATE,112) + isnull(c.EMPLOYEE_NR,d.EMPLOYEE_NR) Collate SQL_Latin1_General_CP1_CI_AS = f.[EmployeeKey] Collate SQL_Latin1_General_CP1_CI_AS
where a.Queue_Taype = 'Tax Queue'
drop table #Tax_Admin
条款,但是没有用。我已经尝试构建一个Null表,然后更新信息,这些信息不起作用。
有人可以帮帮我吗?
答案 0 :(得分:0)
在SSRS中创建临时表有什么问题?我进行了快速测试以确保您可以在SSRS 2012中执行此操作,并且看起来这样运行正常,例如我的数据集定义为:
CREATE TABLE #temp(id INT, name VARCHAR(10));
INSERT INTO #temp SELECT 1, 'Harry';
INSERT INTO #temp SELECT 2, 'Megan';
SELECT * FROM #temp;
当您尝试在SSRS中执行此操作时,您获得的实际错误是什么?
如果你无法使用它,那么你可以创建一个存储过程(没有参数),只需将你的脚本粘贴到那里,然后使用Query Type = Stored Procedure并选择你刚刚在SSRS中创建的那个。 / p>
使用WITH
时最常见的问题是您的上一个语句未正确终止;
,但在您的脚本中似乎不是这样吗?人们经常;WITH
来解决这个问题。
您可以尝试使用表变量,即将#Tax_Admin更改为@Tax_Admin,将DECLARE
更改为TABLE
。