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' beginINSERT 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 UserTypeswhere (UserTypeID=@UserTypeID) endwhen i execute the stored procedure it works fine on insert and updatethe problem in delete i just want del by UserTypeIDits 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 caselike belowALTER procedure [dbo].[ManageUserTypes](@check nchar(1),@UserTypeID nvarchar(10),@TypeName nvarchar(10) = NULL) ASif @check ='i' beginINSERT INTO UserTypes(UserTypeID ,TypeName )VALUES (@UserTypeID ,@TypeName)endif @check='u' begin UPDATE UserTypesSET TypeName = @TypeNamewhere (UserTypeID=@UserTypeID)endif @check='d' begin DELETE FROM UserTypeswhere (UserTypeID=@UserTypeID)endand while calling execute like thisEXEC [dbo].[ManageUserTypes] 'd',<value for usertypeid> ------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/https://www.facebook.com/VmBlogs |
|
|
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 |
|
|
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 MVPhttp://visakhm.blogspot.com/https://www.facebook.com/VmBlogs |
|
|
jasmen
Starting Member
11 Posts |
Posted - 2014-02-12 : 12:32:12
|
pls can u write itbecause i did it like this and i get the same errorDELETE FROM UserTypes WHERE (UserTypeID = @UserTypeID OR @TypeName IS NULL) end |
|
|
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 KizerSQL Server MVP since 2007http://weblogs.sqlteam.com/tarad/ |
|
|
jasmen
Starting Member
11 Posts |
Posted - 2014-02-12 : 13:18:54
|
tkizer,visakh16 thanks its working now |
|
|
tkizer
Almighty SQL Goddess
38200 Posts |
|
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 MVPhttp://visakhm.blogspot.com/https://www.facebook.com/VmBlogs |
|
|
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 KizerSQL Server MVP since 2007http://weblogs.sqlteam.com/tarad/ |
|
|
|