![]() | |
![]() |
| | Thread Tools | Display Modes |
#1
| |||
| |||
|
#2
| |||
| |||
|
|
I needed to run a conditional SQL that include a value from a global variable set prior to the task. For some reason, the conditional (IF) and the global variable couldn't work together. One or the other by itself is OK. Below are the SQL I am using: Case 1 works (with IF): IF ((SELECT COUNT(*) FROM v_AlarmEventHistoryInternal WHERE EventStampUTC (SELECT MAX(EventStampUTC) FROM v_AlarmEventHistoryInternal WHERE EventStampUTC < '9999-12-12') )>5000) PRINT 'OK' Case 2 also works (with global variable): SELECT COUNT(*) FROM v_AlarmEventHistoryInternal WHERE EventStampUTC (SELECT MAX(EventStampUTC) FROM v_AlarmEventHistoryInternal WHERE EventStampUTC < '9999-12-12') AND EventStampUTC > DATEADD(s, 1, ?) Case 3 gets "syntax error or access violation" (with both IF and global variable): IF ((SELECT COUNT(*) FROM v_AlarmEventHistoryInternal WHERE EventStampUTC (SELECT MAX(EventStampUTC) FROM v_AlarmEventHistoryInternal WHERE EventStampUTC < '9999-12-12') AND EventStampUTC > DATEADD(s, 1, ?) )>5000) PRINT 'OK' |
![]() |
| Thread Tools | |
| Display Modes | |
| |