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.
sql-server sql-update ssms
add a comment |
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.
sql-server sql-update ssms
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
add a comment |
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.
sql-server sql-update ssms
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
sql-server sql-update ssms
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
add a comment |
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
add a comment |
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
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
add a comment |
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>;
add a comment |
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
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
add a comment |
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
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
add a comment |
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
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
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
add a comment |
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
add a comment |
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>;
add a comment |
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>;
add a comment |
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>;
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>;
answered Nov 8 at 11:16
Yogesh Sharma
26.3k51334
26.3k51334
add a comment |
add a comment |
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
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
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