Error when using SQL Stored Procedure in VB.NEt

vbamateur

Member
Joined
Aug 24, 2005
Messages
6
Programming Experience
Beginner
I called a store procedure that returns a value in VB.NET and it worked the first time the application runs. However, I notice that if I run the program subsequently after, I get the following error message:

"Subquery returned more than 1 value. This is not permitted when the subquery follows =,!=,<,>,<=,>,< or when the subquery is used as an expression".


Any suggestions?
 
Yeah, post the stored proc... the problem is in there.

Tg
 
CREATE PROCEDURE ValidateEmployerClass
@Employer varchar(10),
@Class varchar(10)
--@Output int

as
declare @Output int


if (select Employer from Class where Class.Employer = @Employer) = NULL
set @output = 1
if (select Employer from Class where Class.Employer = @Employer and Class.Class = @Class) = NULL
set @Output = 2
if (select Employer from Class where Class.Employer = @Employer and Class.Class = @Class) <> NULL
set @output = 3
--select @Output
return @Output
GO
 
One of those selects is resulting in more than one row....
Are you checking to see if a particular record(s) exists?

CREATE PROCEDURE ValidateEmployerClass
@Employer varchar(10),
@Class varchar(10)
--@Output int

as
declare @Output int


if NOT EXISTS (select Employer from Class where Class.Employer = @Employer)
set @output = 1

if NOT EXISTS (select Employer from Class where Class.Employer = @Employer and Class.Class = @Class)
set @Output = 2

if EXISTS (select Employer from Class where Class.Employer = @Employer and Class.Class = @Class)
set @output = 3

return @Output
GO

Tg
 
Cool! Let me know if you need any explanation on how it works.

Tg
 
Back
Top