Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2008 Forums
 Transact-SQL (2008)
 returns NULL first 3-4 queries

Author  Topic 

peo
Starting Member

15 Posts

Posted - 2011-06-19 : 08:22:46
Hi.
I have this query (below) that sometimes returns NULL in all columns, although I know there should be data.
And what is really strange: I test the query in SMS and it also returns all Null, but after running the query unchanged 3-5 times, the data appears!!
Any ideas, someone ?

Select 'Dummy',MAX(TT_OUTDOOR) As TT_OUTDOOR_MAX,ROUND(AVG(TT_OUTDOOR),1) As TT_OUTDOOR_AVG,MIN(TT_OUTDOOR) As TT_OUTDOOR_MIN,MAX(TT_INDOOR) As TT_INDOOR_MAX,ROUND(AVG(TT_INDOOR),1) As TT_INDOOR_AVG,MIN(TT_INDOOR) As TT_INDOOR_MIN,MAX(RH_OUTDOOR) As RH_OUTDOOR_MAX,ROUND(AVG(RH_OUTDOOR),1) As RH_OUTDOOR_AVG,MIN(RH_OUTDOOR) As RH_OUTDOOR_MIN,MAX(RH_INDOOR) As RH_INDOOR_MAX,ROUND(AVG(RH_INDOOR),1) As RH_INDOOR_AVG,MIN(RH_INDOOR) As RH_INDOOR_MIN From [LOGGEDVALUES] Where [PAID] ='000741' and [SMPTime] > '2011-06-19 13:00:00'

/P

webfred
Master Smack Fu Yak Hacker

8781 Posts

Posted - 2011-06-19 : 08:26:58
Maybe the table LOGGEDVALUES is in use and the data stored in the table is changing all the time...


No, you're never too old to Yak'n'Roll if you're too young to die.
Go to Top of Page

peo
Starting Member

15 Posts

Posted - 2011-06-19 : 10:45:56
That was sure one of the problems, as there was no upper timespan limit, new values could enter the table during the query, causing the avg calcs to cancel.

The main problem, however, was that the data I was looking for came from another timezone (-1), so in fact there was no data to return from the hour in the query. When I tested the query, it was some minutes after the hour and suddenly there was data to return.



/P
Go to Top of Page
   

- Advertisement -