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.
| Author |
Topic |
|
gogetthealok_55
Starting Member
2 Posts |
Posted - 2008-09-21 : 02:04:02
|
| i m getting this error when i m trying to execute a stored procedure.Msg 137, Level 15, State 2, Procedure Schema_ID, Line 26Must declare the scalar variable "@Priority_ID".CREATE PROCEDURE Schema_ID -- Add the parameters for the stored procedure here @Scheme_ID nchar(10), @Scheme_Name nvarchar(50)ASBEGIN -- SET NOCOUNT ON added to prevent extra result sets from -- interfering with SELECT statements. SET NOCOUNT ON; DECLARE @Scheme_IDID nchar(10) Insert Scheme(Scheme_ID,Scheme_Name) Values (@Scheme_ID, @Scheme_Name) -- Insert statements for procedure here SELECT @Scheme_IDID = @@Identity Insert into Pri_Sche (Priority_ID, Scheme_ID) Values (@Priority_ID, @Scheme_ID)ENDGO |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2008-09-21 : 02:12:54
|
quote: Originally posted by gogetthealok_55 i m getting this error when i m trying to execute a stored procedure.Msg 137, Level 15, State 2, Procedure Schema_ID, Line 26Must declare the scalar variable "@Priority_ID".CREATE PROCEDURE Schema_ID -- Add the parameters for the stored procedure here @Scheme_ID nchar(10), @Scheme_Name nvarchar(50)ASBEGIN -- SET NOCOUNT ON added to prevent extra result sets from -- interfering with SELECT statements. SET NOCOUNT ON; DECLARE @Scheme_IDID intnchar(10),@Priority_ID int Insert Scheme(Scheme_ID,Scheme_Name) Values (@Scheme_ID, @Scheme_Name) -- Insert statements for procedure here SELECT @Scheme_IDID = @@Identity Insert into Pri_Sche (Priority_ID, Scheme_ID) Values (@Priority_ID, @Scheme_ID)ENDGO
you've not declared variable @Priority_ID. include it in decalre above. Also use SCOPE_IDENTITY instead of @@IDENTITY as latter wont always be returning identity value in same scope (for example, the case where you've an enabled trigger on Scheme table)Also couple of other issues1. Why have you declared @Scheme_IDID as nchar? identity columns always return only integer values so the type should be int2. You've not included statement which assigns value of @Priority_ID. how will you be getting its value? or is it a oparameter that you pass value to? in which case it should be included among parameters list on top. |
 |
|
|
|
|
|
|
|