Querying Database - SQL Structure?

Technical support and scripting issues

Moderators: Dorian (MJT support), JRL

Post Reply
PaulSR
Pro Scripter
Posts: 65
Joined: Mon Aug 05, 2013 2:58 pm
Location: Edinburgh/Peterborough

Querying Database - SQL Structure?

Post by PaulSR » Thu Jun 12, 2014 9:16 am

Hello,

I'm trying to query an external SQL database and return a subset of data based on the fact it is data that was generated in the last twenty minutes. I can return data and get most SQL queries to work but for some reason I can't get this to do what I want.

I construct the date/time and store it in LeadsDateTime variable - my suspiscion is that when the DBQuery> line is passed it isn't resolving the %LeadsDateTime% variable before passing and the database doesn't know what to do with it?

The error message is

"Error in : Database - Line:17 - Parameter object is improperly defined. Inconsistent or incomplete information was provided"

Thanks in advance for any help.

Code: Select all

GetDate>Today
GetTime>TheTimeNow
TimeAdd>TheTimeNow,M,-20,LeadsTime
Let>LeadsDateTime={(%Today%+" "+%LeadsTime%)}

GoSub>GetDatabaseData
GoSub>GetExcelReadyAndUpdate

SRT>GetDatabaseData
DBConnect>Provider=MSDASQL.1;Persist Security Info=False;User ID=USERID;Data Source=DATASOURCE,dbH
DBQuery>dbH,select * FROM tos_data WHERE data_date>%LeadsDateTime% ORDER BY data_date DESC,ReturnedData,NumRecs,NumFields,0
//Check For Data
If>{(%NumRecs%=0) OR (%NumFields%=0)}
    MDL>The Database Is Currently Empty Please Try Again Later.
    DBClose>dbH
    Exit>1
EndIf
//Let>SQL=TRUNCATE tos_data
//DBExec>dbH,SQL,NotNeeded
DBClose>dbH
END>GetDatabaseData

PaulSR
Pro Scripter
Posts: 65
Joined: Mon Aug 05, 2013 2:58 pm
Location: Edinburgh/Peterborough

Re: Querying Database - SQL Structure?

Post by PaulSR » Thu Jun 12, 2014 9:24 am

aaaaand once again I post it then the answer hits me right in the face :

Let>LeadsDateTime={("'"+%LeadsDateTime%+"'")}

Missing quotes on the variable :oops:

User avatar
JRL
Automation Wizard
Posts: 3526
Joined: Mon Jan 10, 2005 6:22 pm
Location: Iowa

Re: Querying Database - SQL Structure?

Post by JRL » Thu Jun 12, 2014 1:35 pm

And what a great response time. Only 8 minutes between posting the question and getting the correct answer. What an amazing forum this is :wink:

Post Reply
cron
Sign up to our newsletter for free automation tips, tricks & discounts