update statement

  • Hi,

       i created a temp table as follows

    create table #tmp

    (PolicyNumber varchar(10) Collate SQL_Latin1_General_CP850_BIN

    , TableCode  varchar(3) Collate SQL_Latin1_General_CP850_BIN

    , SeriesCode varchar(1) Collate SQL_Latin1_General_CP850_BIN

    , IssueAge tinyint

    , Gender    char Collate SQL_Latin1_General_CP850_BIN

    , EffectiveDate smalldatetime

    , WaiverOfPremium decimal

    , ClaimNumber varchar(7) Collate SQL_Latin1_General_CP850_BIN

    , LastName varchar(20) Collate SQL_Latin1_General_CP850_BIN

    , FirstName varchar(15) Collate SQL_Latin1_General_CP850_BIN

    , LossDate datetime

    , InClaimFile bit

    , Recaptured varchar(10) Collate SQL_Latin1_General_CP850_BIN

    )

     

    i just want to write an update statement for my temp table

    Table name from where i want to update  -------GE_Claim

    Column to be updated ---------EffectiveDate

  • Which table are you updating, the temp table or GE Claim?  How are the two tables related?  Can you be a bit more descriptive as to what you want done?

    John Rowan

    ======================================================
    ======================================================
    Forum Etiquette: How to post data/code on a forum to get the best help[/url] - by Jeff Moden

  • Is this post the same as your other post?

    http://qa.sqlservercentral.com/forums/shwmessage.aspx?forumid=8&messageid=328379

    It sounds to me like the same question.  If it is, please do not cross post.  Both of your posts have not provided enough information to answer your question.  Please be more descriptive and include table DDL for all involved tables as well as sample data before and after your update.

    John Rowan

    ======================================================
    ======================================================
    Forum Etiquette: How to post data/code on a forum to get the best help[/url] - by Jeff Moden

  • iam updating temp table.

    both tables have PolicyNumber,SeriesCode,TableCode.EffectiveDate

    i just want to update Effective date column in temp table

  • Another very similar post by you: http://qa.sqlservercentral.com/forums/shwmessage.aspx?forumid=8&messageid=328266

    You'd be better served if you provided enough information to answer your question.

     

    John Rowan

    ======================================================
    ======================================================
    Forum Etiquette: How to post data/code on a forum to get the best help[/url] - by Jeff Moden

  • " iam updating temp table.

    both tables have PolicyNumber,SeriesCode,TableCode.EffectiveDate

    i just want to update Effective date column in temp table"

     

    You want to update the temp table EffectiveDate column with what value?  A value from GE Claim?

    John Rowan

    ======================================================
    ======================================================
    Forum Etiquette: How to post data/code on a forum to get the best help[/url] - by Jeff Moden

  • Agreed, 3 separate threads with 3 variations on essentially the same problem, all lacking various required details, is not the ideal way to go about getting a solution.

    I stopped replying because I felt I was wasting my time. *shrug*

     

     

  • Yes value from GE_Claim

     

    Thanks

  • Well, if your tables are related on PolicyNumber,SeriesCode,TableCode, then your UPDATE would look like:

    UPDATE t

    SET t.EffectiveDate = ge.EffectiveDate

    FROM #tmp t

        INNER JOIN GE_Claim ge

        ON t.PolicyNumber = ge.PolicyNumber

            and t.SeriesCode = ge.SeriesCode

            and t.TableCode = ge.TableCode

     

    You'll need to test this as I have not, but based on what you've posted, I think this is what you are looking for.  You should also look up joining tables, UPDATE, INSERT, DELETE, SELECT in BOL.  Updating one table with a value from another is a very straight forward task that anyone working with SQL Server (or any RDBMS for that matter) should understand. 

    John Rowan

    ======================================================
    ======================================================
    Forum Etiquette: How to post data/code on a forum to get the best help[/url] - by Jeff Moden

  • I bet it would really help if you changed the UPDATE to an INSERT.

    there are no rows in your temporary table - you cannot expect to UPDATE a row that is not in the table.

  • I suppose you could be correct David.  I am assuming that Best has already populated the temp table just because Best is asking for an update statement, but the fact remains that nobody really knows what the purpose of all of this is as Best has not given that kind of detail.  I would guess that whatever Best is attempting does not even need to use a temporary table but without a big picture explanation of where this thread fits in with the end result that Best is attempting to accomplish, its all just assumptions based off of the little bit we know. 

    John Rowan

    ======================================================
    ======================================================
    Forum Etiquette: How to post data/code on a forum to get the best help[/url] - by Jeff Moden

Viewing 11 posts - 1 through 10 (of 10 total)

You must be logged in to reply to this topic. Login to reply