Click here to Skip to main content
15,891,777 members
Please Sign up or sign in to vote.
3.00/5 (2 votes)
Can anyone please help.

I have an SQL 2008 R2 table of customer records and need to edit one of the fields in each reocrd.
E.g

Table "Customers"
Field in each record "Analysis3"
My Code is
SQL
select * from SLCustomerAccount
Update SLCustomerAccount
Set AnalysisCode3= 'O21 Merchant/Commercial Shipping'
where AnalysisCode3 = 'C21 Merchant/Commercial Shipping'

I get this Error message
txt
(2291 row(s) affected)
Msg 512, Level 16, State 1, Procedure UpdateCustomerExport, Line 7
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.

Please help i have little hair and i am pulling more out by the minute.

Thank you
Stephen
Posted
Updated 17-Sep-12 4:04am
v2
Comments
__TR__ 14-Sep-12 6:12am    
"Procedure UpdateCustomerExport" - The update statement looks ok, are you calling any stored procedure after the update statement?
Stephen Finch 14-Sep-12 6:34am    
No that is it.
Stephen Finch 14-Sep-12 6:34am    
PS thank you for your reply
Stephen Finch 17-Sep-12 6:17am    
Does anyone have any other idea's
_Amy 17-Sep-12 10:10am    
Can you write your full procedure here. I think from there only the error is coming. Here, this code seems to be fine.

Are you sure that SLCustomerAccount is a table? If all you are doing is using the two statements you posted, I assume there is some "black magic" going on behind the scenes. Using a statment like the following lets one create a view from the execution of a stored procedure:

SQL
CREATE VIEW dbo.SLCustomerAccount
AS
SELECT TOP(100) PERCENT *
FROM OPENROWSET('SQLOLEDB', 'Trusted_Connection=Yes;Server=(local);Database=NameOfTheDatabasse', 'exec UpdateCustomerExport);


There might be an issue with having a view like that updateable. Your first statement (the select statement) will work fine, but an update on such a view might not be valid.

BTW in your question you also mention some table called "Customer" which does not show up anywhere else in your statements.

Regards,

— Manfred
 
Share this answer
 
v3
hi dear
try this

SQL
Update SLCustomerAccount
Set AnalysisCode3= N'O21 Merchant/Commercial Shipping'
where AnalysisCode3 = N'C21 Merchant/Commercial Shipping'
 
Share this answer
 
Comments
Stephen Finch 14-Sep-12 9:16am    
This doesn't seem to work, i still get this message
Msg 512, Level 16, State 1, Procedure UpdateCustomerExport, Line 7
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.
Mr. Mahesh Patel 14-Sep-12 9:37am    
I have run the query exact written by you and believe me that it was run successfully and also take effect by my table.
I am using the SQLSERVER 2008 R2.
What version you are using
Stephen Finch 14-Sep-12 9:40am    
Yes i am using the same version.

I can't make it out what am i doin wrong.
Stephen Finch 14-Sep-12 9:50am    
as soon as i run the code it goes in to read only mode, but if i don't run code i can manually edit the data. Help!

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900