Question : SSIS SQL Table update from Access

I have a table in an MSSQL 2005 DB that needs to get updated from information within a MS Access 2003 DB.  In a "DataFlow" I am able to create a recordset from Access that contains the "Key Field Value" (GIS_ID) and the "Update Field Value" (PIN_PY).  In my SQL DB, my Access GIS_ID is not a Key field and not in the same row as my PIN_PY.  So I create a GIS recordset that gets my SQL "Key Field Value" (tocid) and GIS_ID and a PIN recordset that gets tocid, prop_id (used to identify PIN row) and PIN_PY.  I then use a "Merge Join" to create a recordset that contains tocid, prop_id, GIS_ID, current PIN_PY, and newPIN_PY.  I then store that to a temp table.

So now I have a temp Table with all my updates.  I then use an "Execute SQL Task" to run the following:
SELECT     tocid, prop_id, PIN_PY
FROM         tmpUpdate
WHERE     (PIN_PY <> newPIN_PY)
OR (PIN_PY is NULL)
OR (newPIN_PY is NULL)

NOTE: The above may need some work :-\  I have not yet found a better way to handle a null situation...

This results in a recordset that lists any item that needs to be updated.  I store this into an "Object" variable to process in a "ForEach Loop".

Now is when I hit a snag.  If I set up input variables, it errors when newPIN_PY is NULL (NULL is not valid string).  So I figured I can set the variable to object instead of string.  This got me into the ForEach Loop, but errored when trying to use the variable in the following:

User::newPIN    Input   NVARCHAR   @PIN
User::tocid        Input   LONG             @TOC
User::prop_id    Input   LONG             @ID

UPDATE propval
SET str_val = ?
WHERE (tocid = ?) AND (prop_id = ?)

I then added a "Script Task" to create my Query as follows:

        Dim sPIN As String = Dts.Variables("newPIN").Value.ToString
        Dim sTOC As String = Dts.Variables("tocid").Value.ToString
        Dim sID As String = Dts.Variables("prop_id").Value.ToString
        If sPIN = "" Then
            sPIN = "NULL"
        End If
        Dts.Variables("QueryUpdate").Value = "UPDATE propval SET str_val = " & sPIN & " WHERE (tocid = " & sTOC & ") AND (prop_id = " & sID & ")"
        Dts.TaskResult = Dts.Results.Success

I then run QueryUpdate from an "Execute SQL Task" and it still errors when newPIN is NULL.

Any ideas on how to update when my value is null?

If I need to take a different approach, I am open to anything... so long as it works reliably.

Answer : SSIS SQL Table update from Access

Also, I assume that str_val allows for NULL entries?

And this query should do what you need:

SELECT
    tocid,
    prop_id,
    PIN_PY
FROM tmpUpdate
WHERE COALESCE(PIN_PY, 'X') <> Coalesce(newPIN_PY, 'Y')

NOTE:  X and Y are fillers - enter values that are not allowed or possible in the field, e.g. CHAR(254) and CHAR(253) or some such.
Random Solutions  
 
programming4us programming4us