Results 1 to 5 of 5
  1. #1
    Join Date
    Nov 2004
    Posts
    5

    Question Unanswered: Updating From one table to another

    Whenever I run this query Iget the following error message. Can anyone tell me why. I get the same error with or without the "Distinct"

    Query:

    update Clients
    set Clients.Siccode = (Select distinct updateSIC.siccode
    from updateSIC
    where Clients.accountnumber = updateSIC.accountnumber)

    Error Message:

    Server: Msg 512, Level 16, State 1, Line 1
    Subquery returned more than 1 value. This is not permitted when the subquery follows =, !=, <, <= , >, >= or when the subquery is used as an expression.
    The statement has been terminated.

    Thanks

  2. #2
    Join Date
    Feb 2004
    Location
    In front of the computer
    Posts
    15,579
    Provided Answers: 54
    There is more than one SIC for at least one client number. Using Min() or Max() would help, but might not produce the results that you want.

    -PatP

  3. #3
    Join Date
    Nov 2002
    Location
    Jersey
    Posts
    10,322
    There's more than 1 per SICCode

    Got the table DDL?
    Brett
    8-)

    It's a Great Day for America everybody!

    dbforums Yak CorralRadio 'Rita
    dbForums Member List
    I'm Good Once as I ever was

    The physical order of data in a database has no meaning.

  4. #4
    Join Date
    Jun 2003
    Location
    Ohio
    Posts
    12,592
    Provided Answers: 1
    Try this to find the offending records:

    Code:
    select	distinct
    	updateSIC.accountnumber,
    	updateSIC.siccode
    from	updateSIC
    	inner join --Dups
    		(Select	accountnumber
    		from	updateSIC
    		group by accountnumber
    		having count(*) > 1) Dups
    	on updateSIC.accountnumber = Dups.accountnumber
    Last edited by blindman; 01-13-05 at 11:48.
    If it's not practically useful, then it's practically useless.

    blindman
    www.chess.com: "sqlblindman"
    www.LobsterShot.blogspot.com

  5. #5
    Join Date
    Nov 2004
    Posts
    5
    Thanks alot. That did the trick.

Posting Permissions

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