SQL query variable for datetime computation for shifts or other

Can I set a variable to:

dateAdd(hour,-9-:shift,dateAdd(day,1-:daysBefore,DATEADD(d, 0, DATEDIFF(d, 0, GETDATE()))))

Does a declare and set combo make a temporary variable that goes away when my query is not being run?

Hello zacharyw.larson,

If the sql commands work in the DB Query Browser, it should work in the named query or other sql bindings. So yes, using the declare and set statements would create that temporary variable as you described.

1 Like

Those are SQL scripting operations and functions performed by your DB. Those are local variables (in the DB) that are thrown away with every query.

JDBC itself doesn't officially support SQL scripts, and using them in Ignition will ruin you for when not using MS SQL Server.


You said ruin me when not using MS SQL Server, like I will be spoiled with functionality not normally available?

Or do you mean data will be corrupted in some circumstances?

Spoiled/bad habits from non-standard MS functionality. Microsoft "lock-in".


MS SQL Server can be configured to accept standard (ANSI) syntax. Highly recommended.