Lookout

cancel
Showing results for 
Search instead for 
Did you mean: 

Citadel ODBC Queries using Lookout SQLexec

AAAARRRRRGGGGGHHHHH!!!!!!!

Why is it so difficult to do queries with SQLexec? I have been trying for
days to get even ONE query to work on the simplest task. I have studied
every Lookout Help file on the subject MANY times and even looked through
some examples that others have provided in this newsgroup. Nothing works!
I always get a "syntax error" or else "unexpected character ". It seems
that every database or version of Excel is expecting the quotes in different
places.

I have been programming nearly my whole life in many different languages,
but this task seems much more complicated that it should be. Does anyone
else have this problem with Lookout and SQLexec?

All I am trying to do is query Citadel for one-minute averages of my data
source. I would like to prompt the user somehow to enter the desired date
and time range and then send the query results to a data table or an Excel
spreadsheet. I have been successful in using the MS Query with Excel 97 so
I can see all of my traces and I know they are in there. Since I have had
no luck using SQLexec so far, I have created a workaround for now that
generates the 1 minute averages using the "Average" object and then log the
results to a "csv" file using the "Spreadsheet" object. This has some
drawbacks since I need to perform some further averaging of my data and
present it back to the user in a Lookout panel (15 minute and 1 hour
averages with data validity calculations).

If anyone has some REAL examples of a working SQLexec function that will do
this task I would be very grateful for some help. I am using Lookout
version 4.01.51 (the latest I believe). Below is an example of a basic
query that I am trying to do (this was copy/pasted from a functioning MS
Query table in Excel 97).

SELECT Traces."LocalTime", Traces."Avg{\\geoff\project1\Exp_1}",
Traces."Avg{\\geoff\project1\Exp_2}"
FROM Traces Traces
WHERE (Traces."LocalTime">"9/13/00 13:00")
AND (Traces."Interval"="01:00")

Thanks in advance,
--
Geoffrey B. Klotz
GK Associates, Inc.
TEL: (805) 523-8700
FAX: (805) 523-1216
EMAIL: gklotz@gkainc.com
0 Kudos
Message 1 of 3
(3,687 Views)
SQL implemented by Citadel ODBC driver is subset of the SQL standard and is
optimized for Citadel performance. The major distinctions are:

1) Database has always two tables TRACES and POINTS (see online help for
more info)
2) You can only perform queries (SELECT statement)
3) You can only search based on LocalTime, UTCTime and Interval columns
(WHERE clause)

A Lookout query can include special commands that perform data transforms to
manipulate and analyze historical data. The AVG transform is one of them.
Avg{Datapoint} returns the TIME WEIGHTED average for Datapoint across a time
range. Time weighted means that the Avg transforms takes into consideration
duration of each value. For example if the Pot1 value across time range is
for the first 25% of the time 0 and for the rest 75% it is 100 then the
average is going to be 25 not 50.
Here is an example how to use the Avg transform in an SQL statement:

SELECT "AVG{\\comp\process1\Pot1}", LocalTime
FROM Traces
WHERE LocalTime > '9/19/2000 6:00:00'
AND LocalTime <= '9/19/2000 18:00:00'
AND Interval = '12:00:00'

This SELECT statement returns one row that represents average value of the
\\comp\process1\Pot1 datapoint across 12 hours time range starting at 6:00AM
and its Timestamp. There is a few important things to notice:

1) The statements are not case sensitive
2) AVG uses curve brackets {} to enclose the datapoint name:
{\\comp\process1\Pot1}
3) The AVG expression is in double quotes: "AVG{\\comp\process1\Pot1}"
4) Time constants can be either in double or single quotes (refer to on-line
help for details on formats)
5) The LocalTime in the select list items (1st row) is optional and in this
case returns the end of the time range ('9/19/2000 18:00:00'). In other
words the average is always "timestamped" with the end of the time range.

The time range across which the average is taken is determined by the
starting LocalTime (LocalTime > '9/19/2000 6:00:00') and the Interval, it is
NOT DETERMINED BY THE ENDING LocalTime (LocalTime <= '9/19/2000 18:00:00').

The AVG transform always try to calculate sequence of averages starting from
the LocalTime, all of them across the specified Interval (12:00). For
example:

1) '9/19/2000 6:00:00' - '9/19/2000 18:00:00' (timestamped as '9/19/2000
18:00:00')
2) '9/19/2000 18:00:00' - '9/20/2000 6:00:00' (timestamped as '9/20/2000
6:00:00')
3) average: '9/20/2000 6:00:00' - '9/20/2000 18:00:00' (timestamped as
'9/20/2000 18:00:00')
....

This is calculated internally, but only rows determined by the ending
LocalTime are returned. In this case it was specified as LocalTime <=
'9/20/2000 18:00:01', so only the first average is returned. The following
example would return the first TWO rows:

SELECT "AVG{\\comp\process1\Pot1}", LocalTime
FROM Traces
WHERE LocalTime > '9/19/2000 6:00:00'
AND LocalTime <= '9/20/2000 6:00:00' <-- this rows has changed
AND Interval = '12:00:00'

Guy McDonnell
"newsgroups.ni.com" wrote in message
news:39c01104@newsgroups.ni.com...
> AAAARRRRRGGGGGHHHHH!!!!!!!
>
> Why is it so difficult to do queries with SQLexec? I have been trying for
> days to get even ONE query to work on the simplest task. I have studied
> every Lookout Help file on the subject MANY times and even looked through
> some examples that others have provided in this newsgroup. Nothing works!
> I always get a "syntax error" or else "unexpected character ". It seems
> that every database or version of Excel is expecting the quotes in
different
> places.
>
> I have been programming nearly my whole life in many different languages,
> but this task seems much more complicated that it should be. Does anyone
> else have this problem with Lookout and SQLexec?
>
> All I am trying to do is query Citadel for one-minute averages of my data
> source. I would like to prompt the user somehow to enter the desired date
> and time range and then send the query results to a data table or an Excel
> spreadsheet. I have been successful in using the MS Query with Excel 97
so
> I can see all of my traces and I know they are in there. Since I have had
> no luck using SQLexec so far, I have created a workaround for now that
> generates the 1 minute averages using the "Average" object and then log
the
> results to a "csv" file using the "Spreadsheet" object. This has some
> drawbacks since I need to perform some further averaging of my data and
> present it back to the user in a Lookout panel (15 minute and 1 hour
> averages with data validity calculations).
>
> If anyone has some REAL examples of a working SQLexec function that will
do
> this task I would be very grateful for some help. I am using Lookout
> version 4.01.51 (the latest I believe). Below is an example of a basic
> query that I am trying to do (this was copy/pasted from a functioning MS
> Query table in Excel 97).
>
> SELECT Traces."LocalTime", Traces."Avg{\\geoff\project1\Exp_1}",
> Traces."Avg{\\geoff\project1\Exp_2}"
> FROM Traces Traces
> WHERE (Traces."LocalTime">"9/13/00 13:00")
> AND (Traces."Interval"="01:00")
>
> Thanks in advance,
> --
> Geoffrey B. Klotz
> GK Associates, Inc.
> TEL: (805) 523-8700
> FAX: (805) 523-1216
> EMAIL: gklotz@gkainc.com
>
>
>
0 Kudos
Message 2 of 3
(3,687 Views)
"Guy McDonnell" wrote:
>SQL implemented by Citadel ODBC driver is

This is an excellent description.
Thanks Guy.

We have worked with NI on a lot of SQL functionality and there are a few
extra things that I can add.

It is possible to use an additional WHERE clause to check if a field is TRUE.
e.g. SELECT * FROM Traces Where Switch1=TRUE

Fully qualified field names is a must in LK4. Citadel stores all the data
in a hierachical folder format and you need to use it to retrieve the data.

If you are using data transforms it is important to make the Interval equal
to the time window that you look at (its defualt is 1 day I think).

Citadel caches data so you will not be able to retrieve data more recent
than the cache zone (default is 30sec
s).

Just a few tips anyway, thanks to the Lookout development team for helping
us with these.
John
0 Kudos
Message 3 of 3
(3,687 Views)