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 2008 Forums
 Transact-SQL (2008)
 problem in Stored Procedure

Author  Topic 

jasmen
Starting Member

11 Posts

Posted - 2014-02-11 : 22:18:25
ALTER procedure [dbo].[ManageUserTypes]
(
@check nchar(1),
@UserTypeID nvarchar(10),
@TypeName nvarchar(10)

)
AS
if @check ='i' begin
INSERT INTO UserTypes
(UserTypeID ,TypeName )
VALUES (@UserTypeID ,@TypeName)
end


if @check='u' begin
UPDATE UserTypes
SET TypeName = @TypeName
where (UserTypeID=@UserTypeID)
end




if @check='d' begin
DELETE FROM UserTypes
where (UserTypeID=@UserTypeID)
end

when i execute the stored procedure it works fine on insert and update
the problem in delete i just want del by UserTypeID
its keep saying
Procedure or Function 'ManageUserTypes' expects parameter '@TypeName', which was not supplied.

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2014-02-12 : 00:22:19
make the other parameter as optional in that case
like below

ALTER procedure [dbo].[ManageUserTypes]
(
@check nchar(1),
@UserTypeID nvarchar(10),
@TypeName nvarchar(10) = NULL

)
AS
if @check ='i' begin
INSERT INTO UserTypes
(UserTypeID ,TypeName )
VALUES (@UserTypeID ,@TypeName)
end


if @check='u' begin
UPDATE UserTypes
SET TypeName = @TypeName
where (UserTypeID=@UserTypeID)
end




if @check='d' begin
DELETE FROM UserTypes
where (UserTypeID=@UserTypeID)
end

and while calling execute like this

EXEC [dbo].[ManageUserTypes] 'd',<value for usertypeid>


------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/
https://www.facebook.com/VmBlogs
Go to Top of Page

jasmen
Starting Member

11 Posts

Posted - 2014-02-12 : 01:40:20
sorry do u mean like that CREATE TABLE [dbo].[UserTypes](
[UserTypeID] [nchar](10) NOT NULL,
[TypeName] [nchar](10) NULL,
CONSTRAINT [PK_UserTypes] PRIMARY KEY CLUSTERED
or how can i make it optional in t-sql
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2014-02-12 : 05:26:55
quote:
Originally posted by jasmen

sorry do u mean like that CREATE TABLE [dbo].[UserTypes](
[UserTypeID] [nchar](10) NOT NULL,
[TypeName] [nchar](10) NULL,
CONSTRAINT [PK_UserTypes] PRIMARY KEY CLUSTERED
or how can i make it optional in t-sql


I meant stored procedure not the table.

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/
https://www.facebook.com/VmBlogs
Go to Top of Page

jasmen
Starting Member

11 Posts

Posted - 2014-02-12 : 12:32:12
pls can u write it
because i did it like this and i get the same error
DELETE FROM UserTypes
WHERE (UserTypeID = @UserTypeID OR @TypeName IS NULL)
end
Go to Top of Page

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2014-02-12 : 12:54:20
Show us your EXEC code. The error is indicating you didn't pass the @UserTypeID column. If you don't intend to pass it for a delete, then you need to make the input parameter optional as viaskh16 mentioned. He showed how to do it already in his first reply. Check the input parameter section of his code.

Tara Kizer
SQL Server MVP since 2007
http://weblogs.sqlteam.com/tarad/
Go to Top of Page

jasmen
Starting Member

11 Posts

Posted - 2014-02-12 : 13:18:54
tkizer,visakh16 thanks its working now
Go to Top of Page

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2014-02-12 : 17:15:34


Tara Kizer
SQL Server MVP since 2007
http://weblogs.sqlteam.com/tarad/
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2014-02-13 : 08:08:58
quote:
Originally posted by jasmen

tkizer,visakh16 thanks its working now



so where did you go wrong?

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/
https://www.facebook.com/VmBlogs
Go to Top of Page

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2014-02-13 : 16:55:20
quote:
Originally posted by visakh16

quote:
Originally posted by jasmen

tkizer,visakh16 thanks its working now



so where did you go wrong?




Jasmen missed your code change for the input parameter.

Tara Kizer
SQL Server MVP since 2007
http://weblogs.sqlteam.com/tarad/
Go to Top of Page
   

- Advertisement -