SQL Server Update Set retrun more than one value











up vote
0
down vote

favorite












I want to populate the column [ID contact] with the column [Référence]. Any clue on how to debug this query?



alter table [DB_Test].[dbo].[Check_Result]
add [ID contact] varchar(200)

update [DB_Test].[dbo].[Check_Result]
set [ID contact] = (select [Référence]
from [DB_Test].[dbo].All_Contracts)


I get this Error:
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.










share|improve this question






















  • You can only add one value on the update and you'll probably need a where clause on the line (select [Reference] from [DB_Test].[dbo].All_Contracts)
    – JonTout
    Nov 8 at 11:14












  • Tried with Join?
    – Prashant Pimpale
    Nov 8 at 11:16










  • How are the tables [Check_Result] and All_Contracts related?
    – Denis Rubashkin
    Nov 8 at 11:17










  • What is the foreign key relationship between dbo.Check_Result and dbo.All_Contacts?
    – Thilina Nakkawita
    Nov 8 at 11:31















up vote
0
down vote

favorite












I want to populate the column [ID contact] with the column [Référence]. Any clue on how to debug this query?



alter table [DB_Test].[dbo].[Check_Result]
add [ID contact] varchar(200)

update [DB_Test].[dbo].[Check_Result]
set [ID contact] = (select [Référence]
from [DB_Test].[dbo].All_Contracts)


I get this Error:
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.










share|improve this question






















  • You can only add one value on the update and you'll probably need a where clause on the line (select [Reference] from [DB_Test].[dbo].All_Contracts)
    – JonTout
    Nov 8 at 11:14












  • Tried with Join?
    – Prashant Pimpale
    Nov 8 at 11:16










  • How are the tables [Check_Result] and All_Contracts related?
    – Denis Rubashkin
    Nov 8 at 11:17










  • What is the foreign key relationship between dbo.Check_Result and dbo.All_Contacts?
    – Thilina Nakkawita
    Nov 8 at 11:31













up vote
0
down vote

favorite









up vote
0
down vote

favorite











I want to populate the column [ID contact] with the column [Référence]. Any clue on how to debug this query?



alter table [DB_Test].[dbo].[Check_Result]
add [ID contact] varchar(200)

update [DB_Test].[dbo].[Check_Result]
set [ID contact] = (select [Référence]
from [DB_Test].[dbo].All_Contracts)


I get this Error:
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.










share|improve this question













I want to populate the column [ID contact] with the column [Référence]. Any clue on how to debug this query?



alter table [DB_Test].[dbo].[Check_Result]
add [ID contact] varchar(200)

update [DB_Test].[dbo].[Check_Result]
set [ID contact] = (select [Référence]
from [DB_Test].[dbo].All_Contracts)


I get this Error:
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.







sql-server sql-update ssms






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Nov 8 at 11:13









Boels Maxence

84




84












  • You can only add one value on the update and you'll probably need a where clause on the line (select [Reference] from [DB_Test].[dbo].All_Contracts)
    – JonTout
    Nov 8 at 11:14












  • Tried with Join?
    – Prashant Pimpale
    Nov 8 at 11:16










  • How are the tables [Check_Result] and All_Contracts related?
    – Denis Rubashkin
    Nov 8 at 11:17










  • What is the foreign key relationship between dbo.Check_Result and dbo.All_Contacts?
    – Thilina Nakkawita
    Nov 8 at 11:31


















  • You can only add one value on the update and you'll probably need a where clause on the line (select [Reference] from [DB_Test].[dbo].All_Contracts)
    – JonTout
    Nov 8 at 11:14












  • Tried with Join?
    – Prashant Pimpale
    Nov 8 at 11:16










  • How are the tables [Check_Result] and All_Contracts related?
    – Denis Rubashkin
    Nov 8 at 11:17










  • What is the foreign key relationship between dbo.Check_Result and dbo.All_Contacts?
    – Thilina Nakkawita
    Nov 8 at 11:31
















You can only add one value on the update and you'll probably need a where clause on the line (select [Reference] from [DB_Test].[dbo].All_Contracts)
– JonTout
Nov 8 at 11:14






You can only add one value on the update and you'll probably need a where clause on the line (select [Reference] from [DB_Test].[dbo].All_Contracts)
– JonTout
Nov 8 at 11:14














Tried with Join?
– Prashant Pimpale
Nov 8 at 11:16




Tried with Join?
– Prashant Pimpale
Nov 8 at 11:16












How are the tables [Check_Result] and All_Contracts related?
– Denis Rubashkin
Nov 8 at 11:17




How are the tables [Check_Result] and All_Contracts related?
– Denis Rubashkin
Nov 8 at 11:17












What is the foreign key relationship between dbo.Check_Result and dbo.All_Contacts?
– Thilina Nakkawita
Nov 8 at 11:31




What is the foreign key relationship between dbo.Check_Result and dbo.All_Contacts?
– Thilina Nakkawita
Nov 8 at 11:31












2 Answers
2






active

oldest

votes

















up vote
1
down vote



accepted










The reason for the error is below query returns multiple [Référence] values.



select [Référence] from [DB_Test].[dbo].All_Contracts


You need to maintain a foreign key relationship between [dbo].[Check_Result] table and [dbo].All_Contracts



After that, you can Join the two tables and update the [ID Contact] from [Référence]



UPDATE C
SET C.[ID contact] = AC.[Référence]
FROM [DB_Test].[dbo].[Check_Result] C
INNER JOIN [DB_Test].[dbo].All_Contracts AC ON AC.FORIEGNKEY_COL = C.FORIEGNKEY_COL





share|improve this answer





















  • I am just trying to take the column [Référence] from table [DB_Test].[dbo].[All_Contractsfrom] and put it into a table called [DB_Test].[dbo].[Check_Result] with new column name [ID contact]
    – Boels Maxence
    Nov 8 at 12:27










  • The relation with the two table depends on [ID Payment] from another table [Expenses]
    – Boels Maxence
    Nov 8 at 12:38


















up vote
0
down vote













I am assuming there is relationship between two table, if so then you can do JOIN :



UPDATE 
cr.[ID contact] = cn.[Référence]
FROM [DB_Test].[dbo].[Check_Result] cr INNER JOIN
[DB_Test].[dbo].All_Contracts cn
ON cr.<col> = cn.<col>;





share|improve this answer





















    Your Answer






    StackExchange.ifUsing("editor", function () {
    StackExchange.using("externalEditor", function () {
    StackExchange.using("snippets", function () {
    StackExchange.snippets.init();
    });
    });
    }, "code-snippets");

    StackExchange.ready(function() {
    var channelOptions = {
    tags: "".split(" "),
    id: "1"
    };
    initTagRenderer("".split(" "), "".split(" "), channelOptions);

    StackExchange.using("externalEditor", function() {
    // Have to fire editor after snippets, if snippets enabled
    if (StackExchange.settings.snippets.snippetsEnabled) {
    StackExchange.using("snippets", function() {
    createEditor();
    });
    }
    else {
    createEditor();
    }
    });

    function createEditor() {
    StackExchange.prepareEditor({
    heartbeatType: 'answer',
    convertImagesToLinks: true,
    noModals: true,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: 10,
    bindNavPrevention: true,
    postfix: "",
    imageUploader: {
    brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
    contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
    allowUrls: true
    },
    onDemand: true,
    discardSelector: ".discard-answer"
    ,immediatelyShowMarkdownHelp:true
    });


    }
    });














     

    draft saved


    draft discarded


















    StackExchange.ready(
    function () {
    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53206599%2fsql-server-update-set-retrun-more-than-one-value%23new-answer', 'question_page');
    }
    );

    Post as a guest















    Required, but never shown

























    2 Answers
    2






    active

    oldest

    votes








    2 Answers
    2






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes








    up vote
    1
    down vote



    accepted










    The reason for the error is below query returns multiple [Référence] values.



    select [Référence] from [DB_Test].[dbo].All_Contracts


    You need to maintain a foreign key relationship between [dbo].[Check_Result] table and [dbo].All_Contracts



    After that, you can Join the two tables and update the [ID Contact] from [Référence]



    UPDATE C
    SET C.[ID contact] = AC.[Référence]
    FROM [DB_Test].[dbo].[Check_Result] C
    INNER JOIN [DB_Test].[dbo].All_Contracts AC ON AC.FORIEGNKEY_COL = C.FORIEGNKEY_COL





    share|improve this answer





















    • I am just trying to take the column [Référence] from table [DB_Test].[dbo].[All_Contractsfrom] and put it into a table called [DB_Test].[dbo].[Check_Result] with new column name [ID contact]
      – Boels Maxence
      Nov 8 at 12:27










    • The relation with the two table depends on [ID Payment] from another table [Expenses]
      – Boels Maxence
      Nov 8 at 12:38















    up vote
    1
    down vote



    accepted










    The reason for the error is below query returns multiple [Référence] values.



    select [Référence] from [DB_Test].[dbo].All_Contracts


    You need to maintain a foreign key relationship between [dbo].[Check_Result] table and [dbo].All_Contracts



    After that, you can Join the two tables and update the [ID Contact] from [Référence]



    UPDATE C
    SET C.[ID contact] = AC.[Référence]
    FROM [DB_Test].[dbo].[Check_Result] C
    INNER JOIN [DB_Test].[dbo].All_Contracts AC ON AC.FORIEGNKEY_COL = C.FORIEGNKEY_COL





    share|improve this answer





















    • I am just trying to take the column [Référence] from table [DB_Test].[dbo].[All_Contractsfrom] and put it into a table called [DB_Test].[dbo].[Check_Result] with new column name [ID contact]
      – Boels Maxence
      Nov 8 at 12:27










    • The relation with the two table depends on [ID Payment] from another table [Expenses]
      – Boels Maxence
      Nov 8 at 12:38













    up vote
    1
    down vote



    accepted







    up vote
    1
    down vote



    accepted






    The reason for the error is below query returns multiple [Référence] values.



    select [Référence] from [DB_Test].[dbo].All_Contracts


    You need to maintain a foreign key relationship between [dbo].[Check_Result] table and [dbo].All_Contracts



    After that, you can Join the two tables and update the [ID Contact] from [Référence]



    UPDATE C
    SET C.[ID contact] = AC.[Référence]
    FROM [DB_Test].[dbo].[Check_Result] C
    INNER JOIN [DB_Test].[dbo].All_Contracts AC ON AC.FORIEGNKEY_COL = C.FORIEGNKEY_COL





    share|improve this answer












    The reason for the error is below query returns multiple [Référence] values.



    select [Référence] from [DB_Test].[dbo].All_Contracts


    You need to maintain a foreign key relationship between [dbo].[Check_Result] table and [dbo].All_Contracts



    After that, you can Join the two tables and update the [ID Contact] from [Référence]



    UPDATE C
    SET C.[ID contact] = AC.[Référence]
    FROM [DB_Test].[dbo].[Check_Result] C
    INNER JOIN [DB_Test].[dbo].All_Contracts AC ON AC.FORIEGNKEY_COL = C.FORIEGNKEY_COL






    share|improve this answer












    share|improve this answer



    share|improve this answer










    answered Nov 8 at 11:36









    Thilina Nakkawita

    888727




    888727












    • I am just trying to take the column [Référence] from table [DB_Test].[dbo].[All_Contractsfrom] and put it into a table called [DB_Test].[dbo].[Check_Result] with new column name [ID contact]
      – Boels Maxence
      Nov 8 at 12:27










    • The relation with the two table depends on [ID Payment] from another table [Expenses]
      – Boels Maxence
      Nov 8 at 12:38


















    • I am just trying to take the column [Référence] from table [DB_Test].[dbo].[All_Contractsfrom] and put it into a table called [DB_Test].[dbo].[Check_Result] with new column name [ID contact]
      – Boels Maxence
      Nov 8 at 12:27










    • The relation with the two table depends on [ID Payment] from another table [Expenses]
      – Boels Maxence
      Nov 8 at 12:38
















    I am just trying to take the column [Référence] from table [DB_Test].[dbo].[All_Contractsfrom] and put it into a table called [DB_Test].[dbo].[Check_Result] with new column name [ID contact]
    – Boels Maxence
    Nov 8 at 12:27




    I am just trying to take the column [Référence] from table [DB_Test].[dbo].[All_Contractsfrom] and put it into a table called [DB_Test].[dbo].[Check_Result] with new column name [ID contact]
    – Boels Maxence
    Nov 8 at 12:27












    The relation with the two table depends on [ID Payment] from another table [Expenses]
    – Boels Maxence
    Nov 8 at 12:38




    The relation with the two table depends on [ID Payment] from another table [Expenses]
    – Boels Maxence
    Nov 8 at 12:38












    up vote
    0
    down vote













    I am assuming there is relationship between two table, if so then you can do JOIN :



    UPDATE 
    cr.[ID contact] = cn.[Référence]
    FROM [DB_Test].[dbo].[Check_Result] cr INNER JOIN
    [DB_Test].[dbo].All_Contracts cn
    ON cr.<col> = cn.<col>;





    share|improve this answer

























      up vote
      0
      down vote













      I am assuming there is relationship between two table, if so then you can do JOIN :



      UPDATE 
      cr.[ID contact] = cn.[Référence]
      FROM [DB_Test].[dbo].[Check_Result] cr INNER JOIN
      [DB_Test].[dbo].All_Contracts cn
      ON cr.<col> = cn.<col>;





      share|improve this answer























        up vote
        0
        down vote










        up vote
        0
        down vote









        I am assuming there is relationship between two table, if so then you can do JOIN :



        UPDATE 
        cr.[ID contact] = cn.[Référence]
        FROM [DB_Test].[dbo].[Check_Result] cr INNER JOIN
        [DB_Test].[dbo].All_Contracts cn
        ON cr.<col> = cn.<col>;





        share|improve this answer












        I am assuming there is relationship between two table, if so then you can do JOIN :



        UPDATE 
        cr.[ID contact] = cn.[Référence]
        FROM [DB_Test].[dbo].[Check_Result] cr INNER JOIN
        [DB_Test].[dbo].All_Contracts cn
        ON cr.<col> = cn.<col>;






        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered Nov 8 at 11:16









        Yogesh Sharma

        26.3k51334




        26.3k51334






























             

            draft saved


            draft discarded



















































             


            draft saved


            draft discarded














            StackExchange.ready(
            function () {
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53206599%2fsql-server-update-set-retrun-more-than-one-value%23new-answer', 'question_page');
            }
            );

            Post as a guest















            Required, but never shown





















































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown

































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown







            Popular posts from this blog

            Schultheiß

            Verwaltungsgliederung Dänemarks

            Liste der Kulturdenkmale in Wilsdruff