471,049 Members | 1,406 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,049 software developers and data experts.

Trigger

I have a table which takes order called ORDER

I need to create a update trigger which fires when a user X makes a transaction else ignore and continue and sleep for n seconds

for update
as
declare @lastuu varchar(6)
declare @orderid decimal(10)
select @lastuu = [last_upd_user] FROM INSERTED
select @orderid = [order_id] FROM INSERTED
if @lastuu='TM_DEV' -- check user value on for Transaction
begin
Update TS_ORDER
set last_upd_date=getdate()
where order_id=@orderid
end

How do I create a timer?
develop a timer on this and/or a method of updating only when the time is every n seconds
Aug 31 '07 #1
5 2342
ck9663
2,878 Expert 2GB
I have a table which takes order called ORDER

I need to create a update trigger which fires when a user X makes a transaction else ignore and continue and sleep for n seconds

for update
as
declare @lastuu varchar(6)
declare @orderid decimal(10)
select @lastuu = [last_upd_user] FROM INSERTED
select @orderid = [order_id] FROM INSERTED
if @lastuu='TM_DEV' -- check user value on for Transaction
begin
Update TS_ORDER
set last_upd_date=getdate()
where order_id=@orderid
end

How do I create a timer?
develop a timer on this and/or a method of updating only when the time is every n seconds
do a loop until you reach the amount of times you want to sleep

curdate = getdate()

while dateadd(ss,10,curdate) <= getdate()
continue


be careful and avoid endless loop


or try waitfor delay
Aug 31 '07 #2
do a loop until you reach the amount of times you want to sleep

curdate = getdate()

while dateadd(ss,10,curdate) <= getdate()
continue


be careful and avoid endless loop


or try waitfor delay

Can you maybe give me a example since getdate() is always sysdate so I ma confused that this will always continues
Sep 3 '07 #3
ck9663
2,878 Expert 2GB
Can you maybe give me a example since getdate() is always sysdate so I ma confused that this will always continues

sorry about that...that's just an algorithm...here's a 3-second timer...

Expand|Select|Wrap|Line Numbers
  1. select 'start:' + cast(getdate() as varchar(15))
  2.  
  3. BEGIN
  4.     WAITFOR DELAY '00:00:3'
  5.     select 'end:' + cast(getdate() as varchar(15))
  6. END
  7. GO
  8.  
Sep 3 '07 #4
sorry about that...that's just an algorithm...here's a 3-second timer...

Expand|Select|Wrap|Line Numbers
  1. select 'start:' + cast(getdate() as varchar(15))
  2.  
  3. BEGIN
  4.     WAITFOR DELAY '00:00:3'
  5.     select 'end:' + cast(getdate() as varchar(15))
  6. END
  7. GO
  8.  

One other thing if I want this trigger to fire and only do an update when the user is not BLA can i just change the statement to read

set ANSI_NULLS ON
set QUOTED_IDENTIFIER OFF
GO
ALTER trigger [dbo].[TS_ORDER_UPD]
on [dbo].[TS_ORDER]
for update
as
declare @lastuu varchar(6)
declare @orderid decimal(10)
select @lastuu = [last_upd_user] FROM INSERTED
select @orderid = [order_id] FROM INSERTED
if @lastuu !='BLA' -- SO only execute update and change time when user is not BLA
begin
Update TS_ORDER
set last_upd_date=getdate()
where order_id=@orderid
end
Sep 4 '07 #5
ck9663
2,878 Expert 2GB
One other thing if I want this trigger to fire and only do an update when the user is not BLA can i just change the statement to read

set ANSI_NULLS ON
set QUOTED_IDENTIFIER OFF
GO
ALTER trigger [dbo].[TS_ORDER_UPD]
on [dbo].[TS_ORDER]
for update
as
declare @lastuu varchar(6)
declare @orderid decimal(10)
select @lastuu = [last_upd_user] FROM INSERTED
select @orderid = [order_id] FROM INSERTED
if @lastuu !='BLA' -- SO only execute update and change time when user is not BLA
begin
Update TS_ORDER
set last_upd_date=getdate()
where order_id=@orderid
end
if you're storing the username on that field, yes. or you may also check the value of SYSTEM_USER system variable. it returns the current username used to connect to the sql server
Sep 5 '07 #6

Post your reply

Sign in to post your reply or Sign up for a free account.

Similar topics

1 post views Thread by Matik | last post: by
6 posts views Thread by Scott CM | last post: by
9 posts views Thread by Martin | last post: by
reply views Thread by JohnO | last post: by
1 post views Thread by deepdata | last post: by
7 posts views Thread by Shane | last post: by
reply views Thread by leo001 | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.