Subquery returned more than 1 value

  • update tblmCIBC

    set c_notes = (SELECT ',rtrim (isnull(n.Datetime,' ' +

    rtrim (isnull(n.NCOLEC,' ' +

    rtrim(isnull(n.NTEXT,' ' +

    rtrim(isnull(n.FLAG,' FROM test_Notes

    why the error?

  • This select

    SELECT ',rtrim (isnull(n.Datetime,' ' +

    rtrim (isnull(n.NCOLEC,' ' +

    rtrim(isnull(n.NTEXT,' ' +

    rtrim(isnull(n.FLAG,' FROM test_Notes

    returned more than 1 row. The = operator implies that there is a single value coming back from this query taht you want the target column to be updated to. With multiple rows coming back, SQL server can't tell which of the multiple values you want to set the target column to.

    You need to add a 'where' clause to limit the rows being returned.

    You may also need to add a 'where' clause to the update too, unless you want all the rows in the table to have the same value.


    And then again, I might be wrong ...
    David Webb

  • Your syntax is all messed up. You have no closing parens on any of your ISNULL's or RTRIM's in addition to numerous other syntactical errors. However, due to the fact that you got the subquery error rather than a syntax error, I'm assuming you simply didn't paste the entire update statement. Please post entire statements in the future.

    Also, your update logic is off. You are trying to set the first value of tblMCICB to the entire dataset of test_notes.

    Try something like:

    update tblmCIBC

    set c_notes =

    RTRIM(ISNULL(n.Datetime,' ')) +

    RTRIM(ISNULL(n.NCOLEC,' ')) +

    RTRIM(ISNULL(n.NTEXT,' ')) +

    RTRIM(ISNULL(n.FLAG,''))

    FROM tblmCICB INNER JOIN test_notes ON blah=blah

    Seth Phelabaum


    Consistency is only a virtue if you're not a screwup. 😉

    Links: How to Post Sample Data[/url] :: Running Totals[/url] :: Tally Table[/url] :: Cross Tabs/Pivots[/url] :: String Concatenation[/url]

Viewing 3 posts - 1 through 2 (of 2 total)

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