Groups | Blog | Home
all groups > sql server programming > april 2004 >

sql server programming : newbie needs help creating SP


Danny Ni
4/8/2004 9:18:23 PM
Hi,

I tried to create a SP:
CREATE PROCEDURE spAddGroup
@Description char(50)
AS
set nocount on
select * from groups where description = @Description
if @@rowcount > 0
select -1
else
begin
insert Groups values(@Description)
select @@identity
end
GO

It's woking. But it returns 2 resultset, 1st one comes from
select * from groups where description = @Description

I want to get rid of this resultset while keeping SP function the same way.
How do I do it?

TIA

Albert Soussana
4/9/2004 12:41:39 AM
Try This
Declare @Counter int
Select @Counter = count(*) from groups where description = @Description
if @Counter> 0
select -1
else
begin
insert Groups values(@Description)
select @@identity
end


[quoted text, click to view]

Hari Prasad
5/9/2004 10:04:43 AM
Hi,

This will not give you any result set;

CREATE PROCEDURE spAddGroup
@Description char(50)
AS
set nocount on
if not exists (select * from groups where description = @Description)
begin
insert Groups values(@Description)
end
GO

Thanks
Hari
MCDBA


[quoted text, click to view]

AddThis Social Bookmark Button