问题描述
set nocount on
declare @max_period30 datetime
declare @max_year int
declare @max_month int
create table #Temp
(inv_month int,inv_year int,action_group varchar(50),submitted_by_action int
)
insert #Temp
select a.start_month,a.start_year,a.action_group,isnull(count(*),0)
from
(select
start_month = datepart(month,tb.start_time),start_year = datepart(year,tc.action_group
from BLAH..the_best tb
left join BLAH..the_categories tc
on tb.action_type = tc.action_type
group by tb.id,tb.start_time,tc.action_group
) a
group by a.start_year,a.start_month,a.action_group
order by a.start_year,a.start_month
SET @max_period30 = (SELECT MAX(CONVERT(DATETIME,(CONVERT(CHAR(2),DATEPART(mm,start_time)) + '-01-' + CONVERT(CHAR(4),DATEPART(yy,start_time))),101))
FROM BLAH..the_best)
SET @max_year = DATEPART(YEAR,@max_period30)
SET @max_month = DATEPART(MONTH,@max_period30)
DELETE FROM #Temp
WHERE inv_year = @max_year
AND inv_month = @max_month
INSERT #Temp
SELECT inv_month,inv_year,'Total',SUM(submitted_by_action)
FROM #Temp
GROUP BY inv_month,action_group
UPDATE #Temp
SET action_group = 'No Action Type'
WHERE action_group IS NULL
INSERT #Temp
SELECT DATEPART(MONTH,DATEADD(MONTH,-1,@max_period30)),DATEPART(YEAR,0
FROM
(SELECT disTINCT action_group FROM BLAH..the_categories
UNION
SELECT 'No Action Type') a
LEFT JOIN
(SELECT disTINCT inv_month,action_group FROM #Temp) b
ON a.action_group = b.action_group
WHERE b.action_group IS NULL
EXEC Crosstab
'select ''Tname''= ''T031'',inv_month,action_group,submitted_by_action from #Temp','action_group','sum(submitted_by_action)[]','Tname,inv_month','','inv_year,inv_month'
错误:
Msg 102,Level 15,State 1,Line 1
Incorrect Syntax near ','.
Msg 102,Line 1
Incorrect Syntax near 'A'.
此处继承了运行此存储的proc的sql新手。直到本月的运行,它可能已经有十年没有变化了,并且没有任何问题。
我最多可以缩小范围的是最后的Crosstab部分。但是我不知道该错误是指“ A”还是“ A”。
有人看到此错误指向的地方吗?任何帮助/输入表示赞赏。
谢谢!
不幸的是,我无法真正解释数据的原始外观,但预期的输出是这样的
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)