[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

sql server query works in select but not in update.

Posted on 2016-09-12
3
Medium Priority
?
80 Views
Last Modified: 2016-09-12
I have a super query ID: 41792646 that gives me the sum of the ascii chararcters in a string word. The string only ever contains one word. if i do:

select word, dbo.func_ASCIIEncodeString(TblCurrentWords.word) as AsciiSum
from TblCurrentWords

Open in new window


I get output (the words are not duplicated in the tblcurrentwords) yet when I do:
UPDATE TblCurrentWords
SET AsciiEncode = (
select dbo.func_ASCIIEncodeString(TblCurrentWords.word)
from TblCurrentWords

)

Open in new window


I get error:
Msg 512, Level 16, State 1, Line 5
Subquery returned more than 1 value. This is not permitted when the subquery follows =, !=, <, <= , >, >= or when the subquery is used as an expression.

assistance would be appreciated.
0
Comment
Question by:PeterBaileyUk
3 Comments
 
LVL 11

Expert Comment

by:HuaMinChen
ID: 41793806
Try
UPDATE TblCurrentWords
SET AsciiEncode = (
select top 1 dbo.func_ASCIIEncodeString(TblCurrentWords.word)
from TblCurrentWords
)

Open in new window

0
 
LVL 36

Accepted Solution

by:
ste5an earned 2000 total points
ID: 41793810
Your SELECT return a tuple ( word, word, dbo.func_ASCIIEncodeString(word) ). This means there is a correlation.

You need this correlation also in your UPDATE. E.g.

UPDATE  W
SET     W.AsciiEncode = dbo.func_ASCIIEncodeString(W.word)
FROM    TblCurrentWords W;

Open in new window

0
 

Author Closing Comment

by:PeterBaileyUk
ID: 41793819
thank you Ste5an
0

Featured Post

 [eBook] Windows Nano Server

Download this FREE eBook and learn all you need to get started with Windows Nano Server, including deployment options, remote management
and troubleshooting tips and tricks

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

An alternative to the "For XML" way of pivoting and concatenating result sets into strings, and an easy introduction to "common table expressions" (CTEs). Being someone who is always looking for alternatives to "work your data", I came across this …
Ready to get certified? Check out some courses that help you prepare for third-party exams.
Familiarize people with the process of utilizing SQL Server functions from within Microsoft Access. Microsoft Access is a very powerful client/server development tool. One of the SQL Server objects that you can interact with from within Microsoft Ac…
Via a live example, show how to backup a database, simulate a failure backup the tail of the database transaction log and perform the restore.
Suggested Courses

834 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question