Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 281817
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T05:14:08+00:00 2026-05-12T05:14:08+00:00

I want to update TableA with values from TableB on a nightly basis. Right

  • 0

I want to update TableA with values from TableB on a nightly basis. Right now, I’m trying to do this with SSIS 2005 using a Script Task with the SQL in it. Each time I try to do the update in this manner, I get a time-out error.

Is there a better way to do this in SSIS?

Current information below:

Public Sub Main()

    Const Component_Name As String = "Updating TableA Data"
    Const Conn_String As String = "Data Source=DB_A;Initial Catalog=TableA;Integrated Security=SSPI;"

    Const sql_Emp As String = "Update TableA Set Contract = c.License_No, SEIN = convert(varchar, c.Lic_Exp_Date, 101) " _
        & "From Server.DB_B.dbo.TableB c Inner Join TableA b on " _
        & "rtrim(ltrim(c.business_lic)) = rtrim(ltrim(cast(b.Account_Key as varchar(14)))) " _
        & "Where c.Lic_Exp_Date = (select Max(Lic_Exp_Date) From Server.DB_B.dbo.TableB " _
        & "Where rtrim(ltrim(business_lic)) = rtrim(ltrim(cast(b.Account_Key as varchar(14))))) " _
        & "and convert(varchar, c.Lic_Exp_Date, 101) <> convert(varchar, b.SEIN, 101)"

    Dim con As SqlConnection = New SqlConnection(Conn_String)

    Try
        Dts.Log("Opening DB Connection: " & con.ConnectionString, 0, Nothing)

        con.Open()

        Dim duh As New SqlCommand(sql_Emp, con)
        duh.ExecuteNonQuery()

        con.Close()

        Dts.Log(String.Format(Component_Name), 0, Nothing)
        Dts.Events.FireInformation(0, Component_Name, String.Format("TableA Data Updating"), "", 0, True)

        Dts.TaskResult = Dts.Results.Success

    Catch ex As Exception
        Dts.Events.FireError(0, Component_Name, ex.Message, "", 0)
        Dts.Log("Exception detected: " & ex.ToString, 0, Nothing)
        Dts.TaskResult = Results.Failure

    End Try

End Sub
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-12T05:14:09+00:00Added an answer on May 12, 2026 at 5:14 am

    Let’s start by cleaning that up a little:

    Public Sub Main()
    
        Const Component_Name As String = "Updating TableA Data"
        Const Conn_String As String = "Data Source=DB_A;Initial Catalog=TableA;Integrated Security=SSPI;"
    
        Const sql_Emp As String = _
                "UPDATE TableA" _ 
                 + " SET Contract = c.License_No, SEIN = convert(varchar, c.Lic_Exp_Date, 101)" _
             + " FROM Server.DB_B.dbo.TableB c" _
             + " INNER JOIN TableA b" _
                 + " ON rtrim(ltrim(c.business_lic)) = rtrim(ltrim(cast(b.Account_Key as varchar(14))))" _
             + " WHERE c.Lic_Exp_Date= (" _
                 + " SELECT MAX(Lic_Exp_Date)" _
                 + " FROM Server.DB_B.dbo.TableB" _
                 + " WHERE rtrim(ltrim(business_lic)) = rtrim(ltrim(cast(b.Account_Key as varchar(14))))" _
                + ") AND convert(varchar, c.Lic_Exp_Date, 101) <> convert(varchar, b.SEIN, 101)"
    
        Try
            Using con As New SqlConnection(Conn_String), _
                  cmds New SqlCommand(sql_Emp, con)
    
                Dts.Log("Opening DB Connection: " & con.ConnectionString, 0, Nothing)
    
                con.Open()
                cmd.ExecuteNonQuery()
    
                Dts.Log(String.Format(Component_Name), 0, Nothing)
                Dts.Events.FireInformation(0, Component_Name, String.Format("TableA Data Updating"), "", 0, True)
                Dts.TaskResult = Dts.Results.Success
            End Using
    
        Catch ex As Exception
            Dts.Events.FireError(0, Component_Name, ex.Message, "", 0)
            Dts.Log("Exception detected: " & ex.ToString, 0, Nothing)
            Dts.TaskResult = Results.Failure
    
        End Try
    
    End Sub
    

    Okay, now that I can read it I can start looking at what might be broken. Check back in a few minutes for edits.


    Okay, now let’s look at that query. I’m missing some data type information, so I’m going to make some assumptions. Please correct any that are wrong:

    • b.Account_Key is some number type, probably int. Otherwise you wouldn’t need to convert to varchar
    • The Lic_Exp_Date columns really are of type datetime

    If those are correct, I think this will do what you want, but do it a lot faster:

    UPDATE TableA
        SET Contract = c1.License_No, SEIN = DATEADD(dd,0, DATEDIFF(dd,0, c1.Lic_Exp_Date))
     FROM TableA b
     INNER JOIN Server.DB_B.dbo.TableB c1
         ON ISNUMERIC(c1.busines_lic) = 1 AND cast(c1.business_lic AS int) = b.Account_Key
     INNER JOIN 
         (
            SELECT business_lic, MAX(Lic_Exp_Date) AS Lic_Exp_Date 
            FROM Server.DB_B.dbo.TableB
            GROUP BY business_lic, License_No
         ) c2 ON c2.business_lic = c1.business_lic AND c1.Lic_Exp_Date=c2.Lic_Exp_Date
     WHERE DATEADD(dd,0, DATEDIFF(dd,0, c1.Lic_Exp_Date)) <> DATEADD(dd,0, DATEDIFF(dd,0, b.SEIN))
    

    Here’s what changed:

    • Turn the correlated subquery into a join. A join will be much faster, however the query optimizer might have been doing this for you already
    • Eliminate the need to call a number of per-row functions – should also help you match up with indexes better.
    • Use an integer comparison rather than string for your main join
    • Use date functions rather than convert to strings to remove the time portion, which should be much faster and in turn allow me to:
    • Use date comparisons rather than string comparisons in your join
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

update tableA set tableA.column1 = 'someValue' where tableA.column2 in ( select column3 from tableB
I am using Visual Studio 2008 and Sql Server 2005 I want to update
I'm trying to update a table based on the sum of values from another
I want to update a table based on the values from another table. If
Im trying to update someone else's Rails app. Right now, an HTML table displays
I want to accomplish this (mysql) query: UPDATE table SET field = field +
I'm building a table from which I want to update different fields of a
I'd like to update values in one table based on corresponding values from other
I want to change the values of column this in table_one where this =
I'm trying to update my database i.e. a MS Access file, I want to

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.