读书人

多线程同时执行一个存储过程如何才能

发布时间: 2012-03-25 20:55:17 作者: rapoo

多线程同时执行一个存储过程,怎么才能取到不同的数据。
ALTER PROCEDURE [dbo].[sp_tmp_ad_GetIDS]
(
@TaskID int,
@sid int,
@n int
)
AS
BEGIN
declare @table table(id int,keyword nvarchar(200))
declare @keywordid int
declare @gettime datetime
select @gettime=getdate()
update dbo.map_job_task set gettime=@gettime where TaskID=@TaskID and sid=@sid
select @keywordid=keywordid from dbo.map_job_task where TaskID=@TaskID and sid=@sid and gettime=@gettime
update dbo.map_job_task set keywordid=keywordid+@n where TaskID=@TaskID and sid=@sid and gettime=@gettime
if(@@rowcount> 0)
begin
insert into @table
select top(@n) id,keyword from dt_keyword where id> @keywordid and tag is null order by id
select * from @table
end
else
exec sp_tmp_ad_GetIDS @TaskID,@sid,@n
--sp_tmp_ad_GetIDS
END

[解决办法]
传的参数不同 数据就不同
[解决办法]
对啊,传参变一下就好了

读书人网 >SQL Server

热点推荐