dbTalk Databases Forums  

syntax error or access violation in DTS Execute SQL Task

microsoft.public.sqlserver.dts microsoft.public.sqlserver.dts


Discuss syntax error or access violation in DTS Execute SQL Task in the microsoft.public.sqlserver.dts forum.



Reply
 
Thread Tools Display Modes
  #1  
Old   
Delphine
 
Posts: n/a

Default syntax error or access violation in DTS Execute SQL Task - 12-21-2004 , 06:31 PM






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'



Reply With Quote
  #2  
Old   
Allan Mitchell
 
Posts: n/a

Default Re: syntax error or access violation in DTS Execute SQL Task - 12-22-2004 , 12:25 AM






The Design time is less than forgiving and not as strong as the runtime so
when I encounter things like this with the ? place holder I usually build
the statement bedore the task and assign.

Like this

Global Variables and SQL statements in DTS
(http://www.sqldts.com/default.aspx?205)

--



Allan Mitchell MCSE,MCDBA, (Microsoft SQL Server MVP)
www.SQLDTS.com - The site for all your DTS needs.
www.SQLIS.com - You thought DTS was good. here we show you the new stuff.
www.konesans.com - Consultancy from the people who know


"Delphine" <Delphine (AT) discussions (DOT) microsoft.com> wrote

Quote:
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'





Reply With Quote
Reply




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.3
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.