The Scenario for me is an (I Called) asynchornous Request-and-Process model.
--DDL
Create table Request (
ID uniqueidentifier primary key default newid(),
types int not null, ---RequestType, depend on use case, not
important here.
data varchar(255) not null, --pseudo code, maybe many columns,
depend.
created datetime not null default getdate(),
done bit not null default 0
)
go
create trigger xxxxxxxxxxx on Request for insert as
begin
--Do nothing or DoSomethings which will complete in short time
--And then activate a job which process the Request
exec sp_start job xxxxxxxxxxxxxxxxxxxx
end
go
Client-Side (C/S or asp.net) insert something by using
insert into Request (types, data)
The job named xxxxxxxxxxxxxxxxxxxx will auto activate by system every hour
or activate by Request_Insert_Trigger. There is nothing to do for the job
but just exec MyProcessSP. In MyProcessSP, there is a loop to call
DoMyProcessSP @ID as descripted in last post.
create procedure DoMyProcessSP (@ID uniqueidentifier) as
begin
declare @types int
declare @data varchar(255)
--pseudo code
select @types=types, @data=data
from Request
where id=@id
if @types=0
begin
insert into Another_A table (xxxxxxxxxxxxxxxxxxxx)
values (data)
exec DoAnotherProcessA @ID --Depend on business rule. Maybe very
complex and take a long time.
end
else if @type=1
begin
insert into Another_B table (xxxxxxxxxxxxxxxxxxxx)
values (data)
exec DoAnotherProcessB @ID --Depend on business rule. Maybe very
complex and take a long time.
end
else
begin
insert into Another_B table (xxxxxxxxxxxxxxxxxxxx)
values (data)
exec DoAnotherProcessC @ID --Depend on business rule. Maybe very
complex and take a long time.
end
update request
set Done=1
where id=@id
end
go
create procedure MyProcessSP as ---A caller in sequent order
begin
--pseudo code
declare @ID uniqueidentifier
declare MyCursor cursor local for
select id
from request
where created>thedate
order by created
for read only
open MyCursor
while (1=1)
begin
fetch next from MyCursor into @ID
if @@fetch_status<>0
break
exec DoMyProcessSP @ID
end
close MyCursor
deallocate MyCursor
end
go
"Razvan Socol" <rsocol@gmail.com>
???????:1136013807.311645.156520@g49g2000cwa.googlegroups.com...
[quoted text, click to view] > Hi, Frank
>
> You can do something this:
>
> declare @ID int
>
> set @ID=(
> select top 1 id from table
> where created>thedate
> order by created, id
> )
>
> while @ID is not null begin
> exec DoSomething(@ID)
>
> set @ID=(
> select top 1 id from table
> where created>thedate
> and id>@ID
> order by created, id
> )
> end
>
> But this method would not have a better performance than a cursor. The
> real solution is to rewrite the DoSomething procedure to process all
> rows at once. That's what SQL is for: set-based operations. Please tell
> us what DoSomething is supposed to do, or post the actual procedure,
> along with DDL (CREATE TABLE-s) and sample data (INSERT INTO ... VALUES
> ...), so we can really help.
>
> Razvan
>