Results 1 to 9 of 9

Thread: ACCESS to MSSQL Update Query

  1. #1
    Join Date
    Oct 2005
    Posts
    5

    ACCESS to MSSQL Update Query

    I run the following statement from an update query in access but I can't find the way to run this same query in MSSQL. Please give me some ideas how to modify and run this in MSSQL.

    Thank you

    "UPDATE DISTINCTROW ZipToTerr, leadsUS SET leadsUS.Terr = [ZipToTerr]![TerrNum] WHERE ((([ZipToTerr].[BU]='W') AND (([ZipToTerr].[ZipFrom])<=[zip]) And (([ZipToTerr].[ZipTo])>=[zip])) And (([leadsUS].[terr]) = 1 ));"

  2. #2
    Join Date
    Sep 2002
    Posts
    5,938
    Tried this?

    UPDATE ZipToTerr, leadsUS SET leadsUS.Terr = [ZipToTerr].[TerrNum] WHERE ((([ZipToTerr].[BU]='W') AND (([ZipToTerr].[ZipFrom])<=[zip]) And (([ZipToTerr].[ZipTo])>=[zip])) And (([leadsUS].[terr]) = 1 ))

  3. #3
    Join Date
    Oct 2005
    Posts
    5
    no didn't work

  4. #4
    Join Date
    Sep 2002
    Posts
    5,938
    Any error message? Where is the table?

  5. #5
    Join Date
    Nov 2002
    Location
    New Jersey, USA
    Posts
    3,932
    In SQL Server you can only have one table in UPDATE statement. If you need to join them to update a table, then you have to use FROM clause.

  6. #6
    Join Date
    Oct 2005
    Posts
    5

    Update From Set

    Thanks for the help.
    I have never used the FROM and UPDATE together. Would you mind to give me some hints on the syntax.
    Thank you

    UPDATE leadsUS
    FROM ZipToTerr
    SET leadsUS.Terr = [ZipToTerr].[TerrNum]
    WHERE ((([ZipToTerr].[BU] = 'W') AND (([ZipToTerr].[ZipFrom]) <= [zip]) AND (([ZipToTerr].[ZipTo]) >= [zip])) AND (([leadsUS].[terr]) = 1))

  7. #7
    Join Date
    Sep 2002
    Posts
    5,938
    Should be:

    UPDATE leadsUS
    SET leadsUS.Terr = [ZipToTerr].[TerrNum] FROM ZipToTerr
    WHERE ((([ZipToTerr].[BU] = 'W') AND (([ZipToTerr].[ZipFrom]) <= [zip]) AND (([ZipToTerr].[ZipTo]) >= [zip])) AND (([leadsUS].[terr]) = 1))

  8. #8
    Join Date
    Oct 2005
    Posts
    5

    Thumbs up

    You are the best!
    It works, thanks you all for the help!

  9. #9
    Join Date
    Sep 2002
    Posts
    5,938
    You can find t-sql syntax and lof of sample codes in sql books online.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •