Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2000 Forums
 Transact-SQL (2000)
 help

Author  Topic 

blackX
Posting Yak Master

102 Posts

Posted - 2008-01-08 : 10:46:02
I created a stored procedure this morning and it compiled fine. I then started working on a new vb project. Now when I run the stored proc it gives me this SQL error:
Subquery returned more than 1 value. This is not permitted when the subquery follows =, !=, <, <= , >, >= or when the subquery is used as an expression.

Here is the procedure:

USE [Premier]
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
create procedure [dbo].[SalesTeamInfoInsert]
(
@begin smalldatetime,
@end smalldatetime
)
as
INSERT INTO salesteaminfo
(
teamid,
teamcommissionpercent,
teamstartdate,
teamenddate
)
SELECT
(select distinct salesrep from member where prestndate between @begin and @end)
, 11.38
, @begin
, @end

THANKS for any help you can give!

khtan
In (Som, Ni, Yak)

17689 Posts

Posted - 2008-01-08 : 10:51:40
the error is here
quote:
(select distinct salesrep from member where prestndate between @begin and @end)

this statement, a sub-query is returning more than one row of result.

try this

SELECT distinct salesrep
, 11.38
, @begin
, @end
from member
where prestndate between @begin and @end



KH
[spoiler]Time is always against us[/spoiler]

Go to Top of Page

blackX
Posting Yak Master

102 Posts

Posted - 2008-01-08 : 11:38:09
quote:
Originally posted by khtan

the error is here
quote:
(select distinct salesrep from member where prestndate between @begin and @end)

this statement, a sub-query is returning more than one row of result.

try this

SELECT distinct salesrep
, 11.38
, @begin
, @end
from member
where prestndate between @begin and @end



KH
[spoiler]Time is always against us[/spoiler]





I want to select more than one rep, I want to insert all distinct reps for the week range
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2008-01-08 : 11:50:45
Try this:-

USE [Premier]
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
create procedure [dbo].[SalesTeamInfoInsert]
(
@begin smalldatetime,
@end smalldatetime
)
as
INSERT INTO salesteaminfo
(
teamid,
teamcommissionpercent,
teamstartdate,
teamenddate
)
SELECT distinct salesrep
, 11.38
, @begin
, @end

from member
where prestndate between @begin and @end

Go to Top of Page

blackX
Posting Yak Master

102 Posts

Posted - 2008-01-08 : 12:55:30
Thanks it work just as described
Go to Top of Page
   

- Advertisement -