Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people, just like you, are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
Solved

sql server query works in select but not in update.

Posted on 2016-09-12
3
51 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 10

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 33

Accepted Solution

by:
ste5an earned 500 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

Enterprise Mobility and BYOD For Dummies

Like “For Dummies” books, you can read this in whatever order you choose and learn about mobility and BYOD; and how to put a competitive mobile infrastructure in place. Developed for SMBs and large enterprises alike, you will find helpful use cases, planning, and implementation.

Question has a verified solution.

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

Everyone has problem when going to load data into Data warehouse (EDW). They all need to confirm that data quality is good but they don't no how to proceed. Microsoft has provided new task within SSIS 2008 called "Data Profiler Task". It solve th…
JSON is being used more and more, besides XML, and you surely wanted to parse the data out into SQL instead of doing it in some Javascript. The below function in SQL Server can do the job for you, returning a quick table with the parsed data.
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…
Viewers will learn how to use the SELECT statement in SQL to return specific rows and columns, with various degrees of sorting and limits in place.

856 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