cancel
Showing results for 
Search instead for 
Did you mean: 

Local variables and select statements?

12-14-2015 5:11 PM
SAP Managed Tags
Subscribe

If I use this in interactive it works:

declare @time1 time
declare @Time2 time
declare @time3 time

select 
    @time1 = t_time1,
    @Time2 = t_time2,
    @time3 = t_time3
from
    tblTimes 
select @time1, @Time2, @time3

But if I try to use it in a procedure I get error on the declares:

declare @time1 time;
declare @Time2 time;
declare @time3 time;

select 
    @time1 = t_time1,
    @Time2 = t_time2,
    @time3 = t_time3
from
    tblTimes;

So my question is how I do this in the best way in a procedure?

Accepted Solutions (1)

Accepted Solutions (1)

Breck_Carter
Participant

The "select @time1 = t_time1" is written using Transact SQL, so the procedure will have to be written using Transact SQL as well...

CREATE PROCEDURE p AS

declare @time1 time
declare @time2 time
declare @time3 time

select 
    @time1 = t_time1,
    @time2 = t_time2,
    @time3 = t_time3
from
    tblTimes 
select @time1, @time2, @time3
go

SELECT * FROM p()
go

If you want to use Watcom SQL (highly recommended!) then use the INTO clause...

CREATE PROCEDURE q()
BEGIN

declare @time1 time;
declare @time2 time;
declare @time3 time;

select 
    t_time1, t_time2, t_time3
into
    @time1, @time2, @time3
from
    tblTimes;

select 
    @time1, @time2, @time3;

END;
SELECT * FROM q();

Answers (0)