消息 102,级别 15,状态 1

flying521 2008-09-23 09:14:48
单纯脚本执行通过,但创建存储过程时提示错误。
错误提示如下:
消息 102,级别 15,状态 1,过程 tj_tjjb,第 50 行
'#tmpjb' 附近有语法错误。
****************************************
create procedure [dbo].[tj_tjjb]
@tjh varchar(20),
@bitxb bit,
@tjfs varchar(50),
@dtstart varchar(10),
@dtend varchar(10)
as

/*
declare @tjh varchar(20)
declare @bitxb bit
declare @tjfs varchar(50)
declare @dtstart varchar(10)
declare @dtend varchar(10)
*/
declare @sql varchar(8000)
declare @tj varchar(100)
BEGIN
--select @tjfs = 'B'
create table #tmpjb(zd varchar(500),xb varchar(20),bs varchar(100),sl int)
/*是否性别分组
*/
--select @tj = ''
if @bitxb = 1
begin
select @tj = ' a.xb, '
end
/**/
select @sql = isnull(@sql + ',' , '') + '[' + bs + ']' from tj_tjfs where name = @tjfs group by bs

if @tjh <> ''
begin
insert into #tmpjb (zd,xb,bs,sl)select a.zd,c.xb,d.bs,1 as sl
from tj_grjb a, tj_lsb b, tjry c,tj_tjfs d
where b.tjh = @tjh and d.name = @tjfs and a.lsbid = b.id and b.dah = c.dah and (c.nl between d.nlxx and d.nlsx)
end

else
begin
insert into #tmpjb (zd,xb,bs,sl)select a.zd,c.xb,d.bs,1 as sl
from tj_grjb a, tj_lsb b, tjry c,tj_tjfs d
where (convert(varchar(10),zjrq,120) between @dtstart and @dtend) and d.name = @tjfs and a.lsbid = b.id and b.dah = c.dah and (c.nl between d.nlxx and d.nlsx)

end


exec('select b.zd, '+ @tjh + @sql +' from (select * from #tmpjb) a pivot (count(sl) for bs in (' + @sql + '))b')

drop table #tmpjb
*********************************************************
...全文
322 1 打赏 收藏 转发到动态 举报
写回复
用AI写文章
1 条回复
切换为时间正序
请发表友善的回复…
发表回复
CN_SQL 2008-09-23
  • 打赏
  • 举报
回复


create procedure [dbo].[tj_tjjb]
@tjh varchar(20),
@bitxb bit,
@tjfs varchar(50),
@dtstart varchar(10),
@dtend varchar(10)
as

/*
declare @tjh varchar(20)
declare @bitxb bit
declare @tjfs varchar(50)
declare @dtstart varchar(10)
declare @dtend varchar(10)
*/
declare @sql varchar(8000)
declare @tj varchar(100)
BEGIN
--select @tjfs = 'B'
create table #tmpjb(zd varchar(500),xb varchar(20),bs varchar(100),sl int)
/*是否性别分组
*/
--select @tj = ''
if @bitxb = 1
begin
select @tj = ' a.xb, '
end
/**/
select @sql = isnull(@sql + ',' , '') + '[' + bs + ']' from tj_tjfs where name = @tjfs group by bs

if @tjh <> ''
begin
insert into #tmpjb (zd,xb,bs,sl)select a.zd,c.xb,d.bs,1 as sl
from tj_grjb a, tj_lsb b, tjry c,tj_tjfs d
where b.tjh = @tjh and d.name = @tjfs and a.lsbid = b.id and b.dah = c.dah and (c.nl between d.nlxx and d.nlsx)
end

else
begin
insert into #tmpjb (zd,xb,bs,sl)select a.zd,c.xb,d.bs,1 as sl
from tj_grjb a, tj_lsb b, tjry c,tj_tjfs d
where (convert(varchar(10),zjrq,120) between @dtstart and @dtend) and d.name = @tjfs and a.lsbid = b.id and b.dah = c.dah and (c.nl between d.nlxx and d.nlsx)

end


exec('select b.zd, '+ @tjh + @sql +' from (select * from #tmpjb) a pivot (count(sl) for bs in (' + @sql + '))b')

drop table #tmpjb
end --这里少个END

34,590

社区成员

发帖
与我相关
我的任务
社区描述
MS-SQL Server相关内容讨论专区
社区管理员
  • 基础类社区
  • 二月十六
  • 卖水果的net
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧