cancel
Showing results for 
Search instead for 
Did you mean: 

Create Event with variable schedule-spec

Baron
Participant
0 Kudos
1,069

Hello, is there any way to use a variable (of type time) in the statement of creating an event?

begin

set @TIME = '09:00';

create event myevent schedule start time @TIME every 5 minutes handler begin end;

end

I tried even with execute immediate without success!!

Accepted Solutions (1)

Accepted Solutions (1)

VolkerBarth
Contributor

This should work with EXECUTE IMMEDIATE when specifying the variable as a literal value, AFAIK. What exactly have you tried?

Baron
Participant
0 Kudos

I am trying to execute this block:

begin

declare @time1 time;

set @time1 = '09:00';

execute immediate ('create event SyncPrAtH schedule start time ''' + convert(varchar(5), @time1) + ''' every 3 minutes handler');

begin

select * from dummy;

end;

end;
VolkerBarth
Contributor
0 Kudos

You have to include the whole CREATE EVENT statement including the handler block as argument to EXECUTE IMMEDIATE.

Baron
Participant
0 Kudos

Oh, Sorry!! I dont know why I was so fast to post it here before looking more closely into my code.

Thank you

VolkerBarth
Contributor
0 Kudos

So does it work now?

Baron
Participant
0 Kudos

Yes, it worked!

Answers (0)