CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 5 of 5

Thread: Update a Table

  1. #1
    Join Date
    Jun 2006
    Posts
    4

    Update a Table

    How can we update TableA based the corresponding value in TableB
    ie I have two table OrgMembers and CopyMembers

    the query is :
    Update OrgMember Set OrgMember.LeftPaid=CopyMember.LeftPaid Where OrgMember.UserID=
    CopyMember.userID


    I get an error :
    The column prefix 'CopyMember' does not match with a table name or alias name used in the query.

    Thanks,
    VK

  2. #2
    Join Date
    Jun 2006
    Location
    Chennai,India
    Posts
    21

    Re: Update a Table

    Hi,

    Just add From Clause with you statment.

    Update OrgMember Set OrgMember.LeftPaid=CopyMember.LeftPaid FROM COPYMEMBER Where OrgMember.UserID=
    CopyMember.userID


    Regards

    Sivar

  3. #3
    Join Date
    Jun 2006
    Posts
    437

    Re: Update a Table

    Hi all,

    Try a query like this

    Update OrgMember O
    Set O.LeftPaid = (SELECT C.LeftPaid
    FROM CopyMember C
    Where O.UserID = C.userID)
    WHERE 0.UserID = (SELECT C.UserID
    FROM CopyMember C
    Where O.UserID = C.userID)

    I haven't tried it, but I think it works correctly.

  4. #4
    Join Date
    Jun 2006
    Posts
    4

    Re: Update a Table

    thanks 4 u r replay

  5. #5
    Join Date
    Oct 2003
    Location
    .NET2.0 / VS2005 Developer
    Posts
    7,104

    Re: Update a Table

    why dont you tell us what database technology youre using first?
    "it's a fax from your dog, Mr Dansworth. It looks like your cat" - Gary Larson...DW1: Data Walkthroughs 1.1...DW2: Data Walkthroughs 2.0...DDS: The DataSet Designer Surface...ANO: ADO.NET2 Orientation...DAN: Deeper ADO.NET...DNU...PQ

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

Featured