Results 1 to 4 of 4

Thread: [RESOLVED] Help on Update table

  1. #1

    Thread Starter
    A SQL Server fool GaryMazzone's Avatar
    Join Date
    Aug 2005
    Location
    Dover,NH
    Posts
    7,493

    Resolved [RESOLVED] Help on Update table

    Using SQL Server 2005

    I have a select statement that finds the data I need

    SQl Code:
    1. Select * from histmasteruser HMU Inner Join meetingbroker.dbo.masteruser MU On Mu.MasterUserID = HMU.MasterUserId and MU.LastModifiedDate < HMU.LastModifiedDate]

    I There a way I can use that in an Update Statement to Update the table Marked MU with the data in specified fields from the table marked HMU?

    UPDATE TABLE statement?
    Sometimes the Programmer
    Sometimes the DBA

    Mazz1

  2. #2
    Super Moderator si_the_geek's Avatar
    Join Date
    Jul 2002
    Location
    Bristol, UK
    Posts
    41,974

    Re: Help on Update table

    If memory serves it is like this:
    Code:
    UPDATE   meetingbroker.dbo.masteruser MU
    SET fieldname = HMU.fieldname
    ...
    
    FROM     histmasteruser HMU 
    WHERE    Mu.MasterUserID = HMU.MasterUserId AND MU.LastModifiedDate < HMU.LastModifiedDate
    ..but I have a sneaking suspicion that you can't use an alias for the MU table, so need to spell it out each time.

  3. #3
    Frenzied Member
    Join Date
    Jan 2006
    Posts
    1,875

    Re: Help on Update table

    you cant use Alias and i doubt even if you can use meetingbroker.dbo. in Update query.
    __________________
    Rate the posts that helped you

  4. #4

    Thread Starter
    A SQL Server fool GaryMazzone's Avatar
    Join Date
    Aug 2005
    Location
    Dover,NH
    Posts
    7,493

    Re: Help on Update table

    Here is what I used (it does work)
    SQL Code:
    1. PRINT 'Tring to Update records'
    2.             UPDATE MeetingBroker.dbo.MasterUser
    3.                 SET MasterUserGuid = HMU.MasterUserGuid,
    4.                     UserName = HMU.UserName,
    5.                     Password = HMU.Password,
    6.                     Email = HMU.Email,
    7.                     IsTemporaryPasswordSet = HMU.IsTemporaryPasswordSet,
    8.                     DatabaseId = HMU.DatabaseId ,
    9.                     CreateDate = HMU.CreateDate,
    10.                     LastModifiedDate = HMU.LastModifiedDate,
    11.                     LastModifiedByUserId = HMU.LastModifiedByUserId
    12.             FROM MeetingBroker.dbo.MasterUser MU
    13.             INNER JOIN histmasteruser HMU ON Mu.MasterUserID = HMU.MasterUserId and MU.LastModifiedDate < HMU.LastModifiedDate

    SI I got it just after I posed.
    Sometimes the Programmer
    Sometimes the DBA

    Mazz1

Posting Permissions

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



Click Here to Expand Forum to Full Width