Home Forums SQL Server 2012 SQL Server 2012 - T-SQL Subquery returned more than 1 value. This is not permitted when the subquery follows RE: Subquery returned more than 1 value. This is not permitted when the subquery follows

  • psingla (6/26/2013)


    use

    if (select TOp 1 UNITE_COUT_MATERIEL from DIM_INTER_MATERIEL)= 'Unité'

    or

    if exists (select 1 from DIM_INTER_MATERIEL where UNITE_COUT_MATERIEL = 'Unité')

    both the above query will work in your case.

    sub query should return single value if you are using =operator to compare/assign the result of the query.

    you'd want to avoid the top 1 example; without a ORDER BY statement, and if that table has multiple rows, there's no way to know if the randomly selected top row would actually be what you were looking for, unless you KNOW that table only ever has a single row in it.

    The EXISTS is my preference, just like you posted here.

    Lowell


    --help us help you! If you post a question, make sure you include a CREATE TABLE... statement and INSERT INTO... statement into that table to give the volunteers here representative data. with your description of the problem, we can provide a tested, verifiable solution to your question! asking the question the right way gets you a tested answer the fastest way possible!