Results 1 to 4 of 4
  1. #1
    Join Date
    Oct 2008
    Posts
    46

    Unanswered: How to update records?

    Can anybody write a script ?
    I have to update NewDate field from Date field. The output of NewDate looks like following dats.

    ID AtID Date NewDate
    1 0 12/12/2007 12/12/2007

    2 1 NULL 12/12/2007

    3 0 10/12/2007 10/12/2007L

    4 1 NULL 10/12/2007

    4 1 NULL 10/12/2007

    4 1 NULL 10/12/2007

    5 0 11/11/2007 11/11/2007

  2. #2
    Join Date
    Dec 2008
    Posts
    1
    Try this,

    begin transaction
    Update <<TABLENAME>> set NEWDATEFIELD = DATEFIELD
    from <<TABLENAME>> T
    where T.[ID] = [ID]

    Select * FROM <<TABLENAME>>

    rollback transaction or commit transaction

  3. #3
    Join Date
    Oct 2008
    Posts
    46
    i hve to update NewDate whre AtID =1 and Date =Null

    Get the value form Date where value =0 and update NewDate where Dave value=1

    I think we have to use loop

  4. #4
    Join Date
    Nov 2004
    Posts
    1,427
    Provided Answers: 4
    Code:
    UPDATE YourTable
    SET NewDate  = ...
    WHERE AtID = 1 AND
         "Date" IS NULL
    ;
    No loop needed, this single SQL-script will update all matching records. BTW, it's bad habit to use type names for column names, like Date.

    Code:
    ID AtID Date NewDate
    1 0 12/12/2007 12/12/2007
    2 1 NULL 12/12/2007
    3 0 10/12/2007 10/12/2007L
    4 1 NULL 10/12/2007
    5 0 11/11/2007 11/11/2007
    Becomes
    Code:
    ID AtID Date NewDate
    1 0 12/12/2007 12/12/2007
    2 1 NULL ...
    3 0 10/12/2007 10/12/2007L
    4 1 NULL ...
    5 0 11/11/2007 11/11/2007
    i hve to update NewDate whre AtID =1 and Date =Null

    Get the value form Date where value =0 and update NewDate where Dave value=1
    Can you restate your question so it becomes clear to someone else what exactly you want?
    With kind regards . . . . . SQL Server 2000/2005/2012
    Wim

    Grabel's Law: 2 is not equal to 3 -- not even for very large values of 2.
    Pat Phelan's Law: 2 very definitely CAN equal 3 -- in at least two programming languages

Posting Permissions

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