Reading data from Navision to SQL Server: Date issues

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • hipo

    Reading data from Navision to SQL Server: Date issues

    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 (datawarehousin g).


    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

  • Simon Hayes

    #2
    Re: Reading data from Navision to SQL Server: Date issues

    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.publi c.sqlserver.dts and/or microsoft.publi c.navision to see
    if there's a better way to handle this.

    Simon

    Comment

    • hipo

      #3
      Re: Reading data from Navision to SQL Server: Date issues

      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 = DTSGlobalVariab les.Parent

      ' Notice here that DTSStep_DTSData PumpTask_1 is the name of the Data
      ' Transformation Task

      Set stp = pkg.Steps("DTSS tep_DTSDataPump Task_1")
      Set tsk = pkg. Tasks(stp.TaskN ame)

      Set cus = tsk.CustomTask

      ' Construct the sql statement

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

      'Assign the SourceSQLStatem ent property of the custom task

      cus.SourceSQLSt atement = sql

      Main = DTSTaskExecResu lt_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

      Comment

      Working...