S
snaker2001
Unregistered / Unconfirmed
GUEST, unregistred user!
CREATE PROCEDURE dbo.statistic_grsta
@user_id char(2) ='',
@r varchar(30) ='',
@grtj_start varchar(10) ='',
@grtj_end varchar(10) =''
AS
--用游标查出用户权限为“业务用户”的用户
declare @user_name varchar(30)
declare user_cursor CURSOR for select name from users_tab where user_qx='业务用户'
open user_cursor
FETCH NEXT FROM user_cursor INTO @user_name
WHILE(@@fetch_status=0)
begin
--用游标得到统计值
declare @sum1 nvarchar(100),@sx_sum1 int
declare @sum2 nvarchar(100),@qx_sum2 int
declare @mainten_sum int
declare @eq_name varchar(100)
declare @insertsql varchar(1024)
set @insertsql='insert into statistic_gr'+@user_id+@r+' values('''+@user_name+''''
declare equip_cursor CURSOR for select equip_name from equipments_tab
open equip_cursor
FETCH NEXT FROM equip_cursor INTO @eq_name
WHILE(@@fetch_status=0)
begin
set @sum1='select @sx_sum = count(*) from givemainten_tab where equip_name='''+@eq_name+''' and mainten_name='''+@user_name+''' and sx_date>='''+@grtj_start+''' and sx_date<='''+@grtj_end+''''
exec sp_executesql @sum1,N'@grtj_start varchar(10),@grtj_end varchar(10),@sx_sum int output',@grtj_start,@grtj_end,@sx_sum1 output
set @sum2='select @qx_sum = count(*) from gomainten_tab where equip_name='''+@eq_name+''' and qx_name='''+@user_name+''' and qx_date>='''+@grtj_start+''' and qx_date<='''+@grtj_end+''''
exec sp_executesql @sum2,N'@grtj_start varchar(10),@grtj_end varchar(10),@qx_sum int output',@grtj_start,@grtj_end,@qx_sum2 output
set @mainten_sum=@sx_sum1+@qx_sum2
set @insertsql=@insertsql+','+convert(varchar(15),@mainten_sum)+')'
FETCH NEXT FROM equip_cursor INTO @eq_name
end
execute(@insertsql)
close equip_cursor
deallocate equip_cursor
end
close user_cursor
deallocate user_cursor
declare @selsql varchar(1024)
set @selsql='select * from statistic_gr'+@user_id+@r
execute(@selsql)
上面的存储过程,我在DELPHI5中调用它,它出现错误提示,说“and附近有语法错误”。那我的and附近就是
set @sum1='select @sx_sum = count(*) from givemainten_tab where equip_name='''+@eq_name+''' and mainten_name='''+@user_name+''' and sx_date>='''+@grtj_start+''' and sx_date<='''+@grtj_end+''''
exec sp_executesql @sum1,N'@grtj_start varchar(10),@grtj_end varchar(10),@sx_sum int output',@grtj_start,@grtj_end,@sx_sum1 output
set @sum2='select @qx_sum = count(*) from gomainten_tab where equip_name='''+@eq_name+''' and qx_name='''+@user_name+''' and qx_date>='''+@grtj_start+''' and qx_date<='''+@grtj_end+''''
exec sp_executesql @sum2,N'@grtj_start varchar(10),@grtj_end varchar(10),@qx_sum int output',@grtj_start,@grtj_end,@qx_sum2 output
set @mainten_sum=@sx_sum1+@qx_sum2
请问上面的语句有错误吗?请指点,不胜感激!!!
@user_id char(2) ='',
@r varchar(30) ='',
@grtj_start varchar(10) ='',
@grtj_end varchar(10) =''
AS
--用游标查出用户权限为“业务用户”的用户
declare @user_name varchar(30)
declare user_cursor CURSOR for select name from users_tab where user_qx='业务用户'
open user_cursor
FETCH NEXT FROM user_cursor INTO @user_name
WHILE(@@fetch_status=0)
begin
--用游标得到统计值
declare @sum1 nvarchar(100),@sx_sum1 int
declare @sum2 nvarchar(100),@qx_sum2 int
declare @mainten_sum int
declare @eq_name varchar(100)
declare @insertsql varchar(1024)
set @insertsql='insert into statistic_gr'+@user_id+@r+' values('''+@user_name+''''
declare equip_cursor CURSOR for select equip_name from equipments_tab
open equip_cursor
FETCH NEXT FROM equip_cursor INTO @eq_name
WHILE(@@fetch_status=0)
begin
set @sum1='select @sx_sum = count(*) from givemainten_tab where equip_name='''+@eq_name+''' and mainten_name='''+@user_name+''' and sx_date>='''+@grtj_start+''' and sx_date<='''+@grtj_end+''''
exec sp_executesql @sum1,N'@grtj_start varchar(10),@grtj_end varchar(10),@sx_sum int output',@grtj_start,@grtj_end,@sx_sum1 output
set @sum2='select @qx_sum = count(*) from gomainten_tab where equip_name='''+@eq_name+''' and qx_name='''+@user_name+''' and qx_date>='''+@grtj_start+''' and qx_date<='''+@grtj_end+''''
exec sp_executesql @sum2,N'@grtj_start varchar(10),@grtj_end varchar(10),@qx_sum int output',@grtj_start,@grtj_end,@qx_sum2 output
set @mainten_sum=@sx_sum1+@qx_sum2
set @insertsql=@insertsql+','+convert(varchar(15),@mainten_sum)+')'
FETCH NEXT FROM equip_cursor INTO @eq_name
end
execute(@insertsql)
close equip_cursor
deallocate equip_cursor
end
close user_cursor
deallocate user_cursor
declare @selsql varchar(1024)
set @selsql='select * from statistic_gr'+@user_id+@r
execute(@selsql)
上面的存储过程,我在DELPHI5中调用它,它出现错误提示,说“and附近有语法错误”。那我的and附近就是
set @sum1='select @sx_sum = count(*) from givemainten_tab where equip_name='''+@eq_name+''' and mainten_name='''+@user_name+''' and sx_date>='''+@grtj_start+''' and sx_date<='''+@grtj_end+''''
exec sp_executesql @sum1,N'@grtj_start varchar(10),@grtj_end varchar(10),@sx_sum int output',@grtj_start,@grtj_end,@sx_sum1 output
set @sum2='select @qx_sum = count(*) from gomainten_tab where equip_name='''+@eq_name+''' and qx_name='''+@user_name+''' and qx_date>='''+@grtj_start+''' and qx_date<='''+@grtj_end+''''
exec sp_executesql @sum2,N'@grtj_start varchar(10),@grtj_end varchar(10),@qx_sum int output',@grtj_start,@grtj_end,@qx_sum2 output
set @mainten_sum=@sx_sum1+@qx_sum2
请问上面的语句有错误吗?请指点,不胜感激!!!