473,473 Members | 4,204 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Subquery returned more than 1 value

3 New Member
I have read quite a bit on the 'Subquery returned more than 1 value'
I understand why and seems obvious, but as I do want multiple records returned I am unsure how to re write this, this looks correct to me.
Does anyone know what im doing wrong here.

SET @CARRIED_FWD=(SELECT ISNULL(REMAINING,0) FROM SV_EMPLOYEE_SICKNESS_CALCULATION
where EMPLOY_REF=@EMPLOY_REF AND SICKNESS_END IN (SELECT MAX(S2.SICKNESS_END)
FROM SV_EMPLOYEE_SICKNESS_CALCULATION S2
WHERE S2.EMPLOY_REF=@EMPLOY_REF ) ) --CH002

Thanks in advance.
Jan 23 '08 #1
4 1568
Delerna
1,134 Recognized Expert Top Contributor
Difficult to say without knowing what you intended to do with @CARRIED_FWD
once you got it

Because you need to keep all records returned then 1 possibility that comes to mind is to keep what you have as a subquery with appropriate fields added so that you can join it to the query where you would have used @CARRIED_FWD

Expand|Select|Wrap|Line Numbers
  1. SELECT your,fields
  2. FROM OtherTableOrView a
  3. JOIN
  4. (SELECT S2.EMPLOY_REF,ISNULL(REMAINING,0) 
  5. FROM SV_EMPLOYEE_SICKNESS_CALCULATION
  6. where EMPLOY_REF=@EMPLOY_REF 
  7.   AND SICKNESS_END IN (SELECT MAX(S2.SICKNESS_END)
  8.                                          FROM SV_EMPLOYEE_SICKNESS_CALCULATION S2 
  9.                                          WHERE S2.EMPLOY_REF=@EMPLOY_REF ) 
  10. )  b on a.???=b.EMPLOY_REF
  11.  
  12.  
Of course you will need to decide for yourself which fields to include and join to
as well as make any other adjustments required to make it work for your situation.

Hope this idea helps but there are plenty of other ways to resolve it.
Jan 23 '08 #2
hdigital
3 New Member
Thanks for your response. would it help if I provided more info
Jan 23 '08 #3
Delerna
1,134 Recognized Expert Top Contributor
If you need more help
Jan 23 '08 #4
hdigital
3 New Member
I sent you a personal message. I was unsure of publishing the full script
Jan 23 '08 #5

Sign in to post your reply or Sign up for a free account.

Similar topics

0
by: leegold2 | last post by:
I tried what's below, seemed OK, so I replaced an "IN" for the "=" in the subquery below because of the subquery's error message. I thought w/"IN" I'd get three (3) records returned as expected....
2
by: Nachi | last post by:
Hi, Urgent Help appreciated.... I am getting resultset with first condition and when try to get the resutlset from second condition i am getting the above error in SQL200. I know that i am...
4
by: Kenny G | last post by:
Below is a query that I currently have. I need to produce a subquery so that the top five of the CodeCount is returned. I appreciate your help. SELECT .PX_SURGEON, .PX_CODE, Count(.PX_CODE)...
5
by: Rod | last post by:
I have a client site where the code below has been working happily for at least four months. The site is using SQL Server 7. The code is ASP.NET Last week an error appeared related to the...
2
by: reap76 | last post by:
I am running the following query: if (select IntExternalAccountID from ExternalAccount) = (select IntExternalAccountID from InternalAccount) select * from InternalAccount where AccountPurpose=2 ...
3
by: Shals | last post by:
Hi, I'm using Form and a subform control within that form. Main form is getting data from one table(Buildings) and subform is getting data from another table(BldgDataByFloor). but both the form...
0
by: fubaba | last post by:
hi, i execute a store procedure got Subquery returned more than 1 value. This is not permitted when the subquery follows =, !=, <, <= , >, >= or when the subquery is used as an expression.'...
0
by: abednegoo | last post by:
Hi All, I tried to find the solution for my problem, but i couldn't find it. If my problem is already solved somewhere, please provide me the link... I'm not a developer myself, but the...
5
by: Anne | last post by:
Hello! Here is the statement in question: --STATEMENT A SELECT * FROM dbo.myTable WHERE colX in (SELECT colX FROM dbo.sourceTable) The problem with Statement A is that 'colX' does not exist...
3
by: jideesh | last post by:
---------------trigger code create trigger DeletepurchaseItems on table_purchaseitems for delete,update as begin select * from deleted update table_STOCK set ostock=(ostock-(select sqty from...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
0
muto222
php
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.