By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
459,457 Members | 1,316 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 459,457 IT Pros & Developers. It's quick & easy.

Reading data from Navision to SQL Server: Date issues

P: n/a
Hi:

I'm trying to read data from Navision 2.60 ERP with own database to a
SQL Server 2000 database via ODBC. All is working except just one
thing, how to filter data with a date field.

I have some big tables that have a date field and I just want to read
data from one or few days, not all the table, cos I will be doing this
every day (datawarehousing).
If I write in my SQL Server DTS:

SELECT *
FROM MYNAVISIONTABLE
WHERE (MYDATE = { d '2005-06-30' })

It works! This notation is the one required by C/ODBC Navision driver.

Now I want to change 2005-06-30 for something like "sysdate" or "today"
or similar... to execute this all days.... any ideas?
THANK YOU,

Regards
Fran

Jul 23 '05 #1
Share this Question
Share on Google+
2 Replies


P: n/a
I don't know anything about Navision, however if you're using a DTS
Execute SQL or Transform Data task, the query executes directly on the
connection, so you should be able to use whatever function Navision has
for the current date (if that makes any sense).

If that doesn't work, then you could look at building up the SQL
statement dynamically (as far as I know, you can't use a variable
inside an ODBC escape clause). One way is to use the DTS COM object
model - build the whole SQL string dynamically, then set the
SQLStatement property of the ExecuteSQLTask object. This could be done
from an ActiveX or Dynamic Properties task in the same package.

If this isn't helpful, you might want to give some more details of
exactly how you're executing the SQL statement within the DTS package.
You should probably also consider posting in
microsoft.public.sqlserver.dts and/or microsoft.public.navision to see
if there's a better way to handle this.

Simon

Jul 23 '05 #2

P: n/a
Hello:

Thank you for your help Simon, the key was to build dynamicaly the SQL
string as you said. Sadly Navision C/ODBC 2.60 driver doesn't seem to
have many features...

I tell you how I did it, in the case someone someday reads this and has
the same problem and wants to solve it fast:

I build a DTS with 2 connections (Origin and Target) and a Data
Transformation Task between them with all the transformation changes I
want. Until here everything as I had before.

My goal is to read only the data that I want filtering it with a date
variable. For example you have some million registers in a table and
want to extract each day just the few new records.

Now I add an ActiveX Task with the following code:
(Probably there's an easiest way to do this, I'm not an expert here,
but this works...)
'************************************************* *********************
' Secuencia de comandos ActiveX Visual Basic
'************************************************* ***********************
Option Explicit

Function Main()
Dim pkg, stp, tsk, cus, sql

'************************************************* ***********************
' Dealing with dates in Navision C/ODBC: They have to be
<{d'aaaa-mm-dd'}>
' Being the first d from date... options: t from time and ts from
timestamp
' The Month function will give you just one number if you are before
October

Dim mes

mes = Month(Date)

If mes <10 Then
mes = "0" & mes
end if

'************************************************* ***********************

Set pkg = DTSGlobalVariables.Parent

' Notice here that DTSStep_DTSDataPumpTask_1 is the name of the Data
' Transformation Task

Set stp = pkg.Steps("DTSStep_DTSDataPumpTask_1")
Set tsk = pkg. Tasks(stp.TaskName)

Set cus = tsk.CustomTask

' Construct the sql statement

sql = "select * from MyTable where (MyDateField > {d'" & Year(Date) &
"-" & mes & "-" & Day(Date) & "'})"

'Assign the SourceSQLStatement property of the custom task

cus.SourceSQLStatement = sql

Main = DTSTaskExecResult_Success
End Function


I put a green (Success) line from this Task to the Origin Connection of
the Data Transformation Task, so that the ActiveX scritp runs the
first, build the SQL sentence, and then the Data Transformation Task
Origin Connection runs the SQL Sentence selecting only the proper data.
You can see this work just looking at the Origin Connection and in the
SQL box you'll see the SQL sentence generated in the last execution of
the DTS.

Thanks!

Regards,
Fran

Jul 23 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.