473,785 Members | 2,480 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Subquery returned more than 1 value. This is not permitted when the subquery follows

1 New Member
hi please help in solving this

i am recieving 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."

for the code



CREATE procedure [dbo].[ADI_spfrmGetLog Entries]
(@frmMasterID int,
@startDate datetime,
@endDate datetime,
@startPos int,
@rowCnt int,
@snapShotDate datetime,
@pagingByDate bit=0,
@ttlCnt int=0 OUTPUT
)
as
begin
SET NOCOUNT ON

--THIS IS USED FOR RESTRICTING NEW RECORDS FROM BEING INCLUDED
--DURING PAGING
if @snapShotDate is null set @snapShotDate=g etdate()

--TABLE TO STORE LOG ENTRIES
CREATE TABLE #TAB
(logRank int identity(1,1),
frmLogEntryID int,
frmRevID int,
dateCreated datetime)

INSERT INTO #TAB
SELECT
l.frmLogEntryID ,
l.frmRevID,
l.dateCreated
FROM
frmRevision r
inner JOIN frmLogEntry l
on r.frmRevID = l.frmRevID
and
(
(@startDate is not null and convert(varchar ,l.dateCreated, 101) >=@startDate)
or
(@startDate is null)
)
and
(
(@endDate is not null and convert(varchar ,l.dateCreated, 101) <= @endDate)
or
(@endDate is null)
)
and convert(varchar ,l.dateCreated, 101) <= @snapShotDate
WHERE r.frmMasterID = @frmMasterID
ORDER BY l.frmlogEntryID desc

--IF PAGING BY EACH DAY, NEED TO GET A LIST OF DISTINCT DATES.
if @pagingByDate =1
BEGIN
DECLARE @dateTab TABLE
(logRank int identity(1,1),
dateCreated datetime)

INSERT INTO @dateTab
SELECT
distinct convert(varchar ,dateCreated,10 1)
FROM #TAB
ORDER BY convert(varchar ,dateCreated,10 1) desc

SELECT
a.frmAttrDispla yName,
a.frmRevID,
l.frmLogEntryID ,
l.dateCreated,
frmAttrValue = CASE
WHEN a.frmAttrName like '%country%'
THEN
ISNULL((select country
from dbo.country
where abbreviation = ld.frmAttrValue ),ld.frmAttrVal ue)
WHEN a.frmAttrName like '%state%'
THEN
ISNULL((select full_name
from dbo.state
where state = ld.frmAttrValue and (StateCountry is NULL or StateCountry <> 'MX')), ld.frmAttrValue )
ELSE ld.frmAttrValue
END,
a.frmAttrID
FROM
#TAB as l
inner join @dateTab as dt
on l.dateCreated >=dt.dateCreate d
and l.dateCreated < dateadd(d,1,dt. dateCreated)
inner join frmAttribute a
on l.frmRevID = a.frmRevID
inner join frmLogEntryDeta il ld
on l.frmLogEntryID =ld.frmLogEntry ID
and a.frmAttrID = ld.frmAttrID
WHERE
dt.logRank = @startPos
Order by a.frmAttrID

if @startPos=1
BEGIN
/*SELECT @ttlCnt = MAX(logRank) from @dateTab*/
SELECT @ttlCnt = MAX(logRank) from #Tab
END

END
ELSE IF @rowCnt=0 and @pagingByDate = 0
BEGIN
SELECT
a.frmAttrDispla yName,
a.frmRevID,
l.frmLogEntryID ,
l.dateCreated,
frmAttrValue = CASE
WHEN a.frmAttrName like '%country%'
THEN
ISNULL((select country
from dbo.country
where abbreviation = ld.frmAttrValue ),ld.frmAttrVal ue)
WHEN a.frmAttrName like '%state%'
THEN
ISNULL((select full_name
from dbo.state
where state = ld.frmAttrValue and (StateCountry is NULL or StateCountry <> 'MX')), ld.frmAttrValue )
ELSE ld.frmAttrValue
END,
a.frmAttrID
FROM
#TAB as l
inner join frmAttribute a
on l.frmRevID = a.frmRevID
inner join frmLogEntryDeta il ld
on l.frmLogEntryID =ld.frmLogEntry ID
and a.frmAttrID = ld.frmAttrID
Order by a.frmAttrID
END
ELSE
BEGIN
DECLARE @endPos INT

SET @endPos = @startPos + @rowCnt
SELECT
a.frmAttrDispla yName,
a.frmRevID,
l.frmLogEntryID ,
l.dateCreated,
frmAttrValue = CASE
WHEN a.frmAttrName like '%country%'
THEN
ISNULL((select country
from dbo.country
where abbreviation = ld.frmAttrValue ),ld.frmAttrVal ue)
WHEN a.frmAttrName like '%state%'
THEN
ISNULL((select full_name
from dbo.state
where state = ld.frmAttrValue and (StateCountry is NULL or StateCountry <> 'MX')), ld.frmAttrValue )
ELSE ld.frmAttrValue
END,
a.frmAttrID
FROM
#TAB as l
inner join frmAttribute a
on l.frmRevID = a.frmRevID
inner join frmLogEntryDeta il ld
on l.frmLogEntryID =ld.frmLogEntry ID
and a.frmAttrID = ld.frmAttrID
WHERE
logRank >= @startPos
and logRank <@endPos
Order by a.frmAttrID

if @startPos=1
BEGIN
SELECT @ttlCnt = MAX(logRank) from #TAB
END
END
DROP TABLE #TAB
SET NOCOUNT OFF

end

GO
Aug 18 '07 #1
0 2070

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

Similar topics

0
1589
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. But when I tried "IN" I got my entire DB returned - I don't show that below - it kept scrolling so I aborted it. What did I do wrong? Seems like the inner just returns three recs. and should match-up w/the outer for three recs. too. I'm using 4.1....
2
2061
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 getting more then one value in the second condition but even i am getting more then one value in my first statement
2
1802
by: Zri Man | last post by:
I have a situation that is as follows: First an Index of what is discussed below: FED_A ->> Federated Objected/Table that has lots of rows LOC_B ->> Local Table which is selected and updated. My data flow works through a Informatica workflow and is therefore not exactly like a single transaction.
5
6595
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 following SQL statement. INSERT INTO OrderItems (ClientID, ProductID, OrderHeaderID, Quantity, Dispatched, BackOrdered) SELECT ClientID, ProductID, 1371 AS OrderHeaderID, Quantity, Dispatched, BackOrdered FROM Basket WHERE RequisitionID = 1369 The...
2
1943
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 and getting the following error Subquery returned more than 1 value. This is not permitted when the subquery follows =, !=, <, <= , >, >= or when the subquery is used as an expression. What I am attempting is if the values in ColumnA from...
3
2921
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 and subform are linked through a child field which is common in both the tables(BuildingNumber). Now, whenever I close the form I receive an error "Subquery returned more than 1 value. This is not permitted when the
0
1281
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.' message is there any one help with these codes below ....... SET @strSQL = (@strSQL + ' AND p.PropertyID NOT IN ( ' + (SELECT DISTINCT a.propertyID FROM propertyAvailability a ...
2
1531
by: neilgilbert1234 | last post by:
Hi Everyone, Im sure this is an easyone, im a newbie to anything half complex in sql so any help would be greatly appreaciated. I have one table that has two values, i need to multiply those values and stick the result back into the table. I have used the script below but getting an error: "Subquery returned more than 1 value. This is not permitted when the subquery follows" Script used: update dbo.PCProjectEntry set...
3
11395
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 deleted)) where itemcode=(select itemcode from deleted)and coid=(select compid from deleted) and fycode=(select financialyear from deleted) end
0
9645
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9480
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10325
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10148
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
9950
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
7499
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5381
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 last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
4053
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 we have to send another system
2
3646
muto222
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.