DB Tag Expression Error

I have setup many alert tags with this expression:

if(dateDiff(toDate(executeScalarQuery("SELECT TOP 1 t_stamp FROM tblBrewWhirlpool ORDER BY t_stamp DESC","FactorySQL")),now(),"minute")>=2 && (toint({[~]Brewhouse/West/WhirlPool/WhirlStatus.Quality},-1)!=192 || {[~]Brewhouse/West/WhirlPool/WhirlStatus}>0),1,0)

For some reason this perticular one keeps giving me an error.

if i remove the toint() around the Quality the tag will save, but it will not evaluate correctly because the value is not an integer.

Thank you,

Where is your tag stored? In the internal database or in an external SQL database? My guess is that the column we store the expression in is only 255 characters long. That is why it would work when you remove the toInt function.

If it is the external database you can alter the strval column on the sqlt_meta table to accept more than 255 characters.

Thanks, I changed the column in the external MS SQL Server database to varchar(MAX) and now the expression will update.

I know this was already fixed, but wouldn’t executeScalarQuery eliminate the need for the TOP 1 in the query? Kind of like saying the first one of the top one… :scratch:

No, executeScalarQuery requires that a single value comes back which means 1 row 1 column.

Okay, then what’s the advantage of using it over a “normal” query that gives you the same result?

Not trying to be odd-- or more than normal. I just can’t quite visualize this yet.

If your query is returning just a single value, by using executeScalarQuery you don’t have to use the square brackets to go inside to get the value out.

Ok! Thanks for the info, Travis!