dbTalk Databases Forums  

returning calculated values from sp as Resultset

comp.databases.sybase comp.databases.sybase


Discuss returning calculated values from sp as Resultset in the comp.databases.sybase forum.



Reply
 
Thread Tools Display Modes
  #11  
Old   
Michael Drewitz
 
Posts: n/a

Default Re: returning calculated values from sp as Resultset - 06-01-2004 , 07:55 AM






Mark A. Parsons wrote:

Quote:
Michael Drewitz wrote:

Since you're getting an error (ie, you're actually submitting something to
the dataserver) could you post the actual (not pseudo) code that you're
working with?

What you want to do (insert values into a temp table and then select all
values as one result set) *IS* doable and fairly straight forward ... but
at this point I can't tell if you're getting errors because of 'syntax' or
'logic' issues. It would be a lot easier to work on this in one languange
(T-SQL as opposed to pseudo-code).
Below is my code. The database is ASA 8.02.3601. If I execute this with
call dba.avg_temperature_values('2004-05-27 09:00:00', '2004-06-27
10:00:00', 5) I get an empty result set.
It seems to be the query in the insert expression because

select avg(fldtemperature) from tblrawdata where
datediff(second, @interval_begin, fldtemperature) > 0

executed on the console causes the error
'ASA error 157: cannot convert 13 to a date'.
If I uncomment the following message, the SP itself causes the same
error. Curious.


CREATE PROCEDURE DBA."avg_temperature_values" @start_time timestamp,
@end_time timestamp, @datepart int
AS
declare @interval_begin timestamp, @interval_end timestamp, @timediff
int, @current_value float
select @timediff = datediff(second, @start_time, @end_time)
select @interval_begin = @start_time

if @datepart = 1 select @interval_end = dateadd(year, 1, interval_begin)
if @datepart = 5 select @interval_end = dateadd(day, 1, @interval_begin)

create table #temp_values(avg_values float)

while @timediff > 0
begin
insert #temp_values(avg_values) select avg(fldtemperature) from
tblrawdata where
datediff(second, @interval_begin, fldtemperature) > 0 and
datediff(second, @interval_end, fldtemperature) < 0
and fldtemperature > -999

-- the message is for debugging purposes but causes an error 'cannot
convert 13 to a date'
--message '#temp_values: ' || (select * from #temp_values) to client

select @timediff = datediff(second, @interval_begin, @end_time)
select @interval_begin = @interval_end

if @datepart = 1 select @interval_end = dateadd(year, 1,
@interval_begin)
if @datepart = 2 select @interval_end = dateadd(month, 1,
@interval_begin)
end

select avg_values from #temp_values

Thanks in advance, Michael


Reply With Quote
  #12  
Old   
Mark A. Parsons
 
Posts: n/a

Default Re: returning calculated values from sp as Resultset - 06-01-2004 , 12:27 PM






Michael Drewitz wrote:

I work with ASE, not ASA, so FWIW ...

Quote:
Below is my code. The database is ASA 8.02.3601. If I execute this with
call dba.avg_temperature_values('2004-05-27 09:00:00', '2004-06-27
10:00:00', 5) I get an empty result set.
It seems to be the query in the insert expression because

select avg(fldtemperature) from tblrawdata where
datediff(second, @interval_begin, fldtemperature) > 0

executed on the console causes the error
'ASA error 157: cannot convert 13 to a date'.
What is the value of 'fldtemperature'? The datediff() function is
expecting the 2nd and 3rd arguments to be valid dates. My guess, without
seeing the actual data, is that the fldtemperature value is not a valid
date.

Quote:
If I uncomment the following message, the SP itself causes the same
error. Curious.

CREATE PROCEDURE DBA."avg_temperature_values" @start_time timestamp,
@end_time timestamp, @datepart int
AS
declare @interval_begin timestamp, @interval_end timestamp, @timediff
int, @current_value float
select @timediff = datediff(second, @start_time, @end_time)
select @interval_begin = @start_time

if @datepart = 1 select @interval_end = dateadd(year, 1, interval_begin)
Not sure if this was a typo ... but you should replace 'interval_begin'
with '@interval_begin' (above).

Quote:
insert #temp_values(avg_values) select avg(fldtemperature) from
tblrawdata where
datediff(second, @interval_begin, fldtemperature) > 0 and
datediff(second, @interval_end, fldtemperature) < 0
and fldtemperature > -999
Again, sounds like fldtemperature is not a valid date ... the name of this
column doesn't look/sound like it stores date values ... and the fact that
you're testing the column for a value '> -999' would appear to confirm my
suspicion.

Are you sure you want to be testing a date value against what appears to be
a temperature (ie, non-date) value?

----------------------

If this still isn't helping you I'd suggest you pop over to the
sybase.public.sqlanywhere.* newsgroups (news server = forums.sybase.com).
Those are ASA-specific groups where you could get more help (assuming the
issue is ASA syntax).

--
Mark A. Parsons

Iron Horse, Inc.
iron_horse (AT) NOSPAM (DOT) compuserve.com


Reply With Quote
Reply




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.3
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.