473,405 Members | 2,445 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,405 software developers and data experts.

Error: Must declare the scalar variable

USE [CP_DOTNET]
GO
/****** Object: StoredProcedure [dbo].[T_sp_SetScreenPermission] Script Date: 06/09/2007 20:15:29 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO




CREATE PROCEDURE [dbo].[T_sp_SetScreenPermission]

@RECEXIST Int output,
@user_Id varchar(10) ,
@Screen_Id varchar(10) ,
@Permission_Id varchar(10) ,
@Created_On Datetime,
@Created_By varchar(50) ,
@machine_ip Varchar(50)


AS
SET NOCOUNT ON;
IF EXISTS (SELECT name FROM sysobjects WHERE name = 'T_SET_SCREEN_PERMISSIONS')
Begin
If exists (select m1.ROLE_ID,m1.USER_ID,m2.DEFAULT_PERMISSION_ID,m2. SCREEN_ID,m2.PERMISSION_ID,m2.IS_ACTIVE
from M_USER m1,M_DEFAULT_SCREEN_PERMISSIONS m2 where m2.IS_ACTIVE='1')SET @RECEXIST = 0

ELSE
Begin
IF EXISTS (SELECT name FROM sysobjects WHERE name = 'T_LOG_FOR_USERS')
Begin
Begin Tran
INSERT INTO T_SET_SCREEN_PERMISSIONS(SET_SCREEN_PERMISSION_ID, USER_ID, SCREEN_ID, PERMISSION_ID,CREATED_ON, CREATED_BY,IS_ACTIVE )

VALUES (@Set_Screen_Permission_Id,@User_Id, @Screen_Id,@Permission_Id,@Created_On, @Created_By,'1' )
DECLARE @Set_Screen_Permission_Id int
set @Set_Screen_Permission_Id = @@identity
Insert into T_LOG_FOR_USERS(TR_DATE,USER_ID,USER_IP_ADDRESS,TR ANSACTION_NAME,TRANSACTION_TABLE_NAME,TRANSACTION_ KEY_FIELD_NAME,TRANSACTION_KEY_FIELD_VALUE,REPORTI NG_FLAG)
Values(@Created_On,@Created_By,@machine_ip,'set Screen Permission Creation','T_SET_SCREEN_PERMISSIONS','SETSCREEN_PE RMISSION_ID',@Set_Screen_Permission_Id,'1')
Commit
SET @RECEXIST = 1
End

Else
Begin
SET @RECEXIST = 3
End
End
End
Else
Begin
SET @RECEXIST = 2
End

Msg 137, Level 15, State 2, Procedure T_sp_SetScreenPermission, Line 30
Must declare the scalar variable "@Set_Screen_Permission_Id".
Jun 9 '07 #1
2 23819
siva538
44
what is the problem you want to ask ... you have to declare the variable before you can use . ... the variable is declared after it is used ..

I suggest you try these kind of simple things before posting to the community ...

Expand|Select|Wrap|Line Numbers
  1.  DECLARE @Set_Screen_Permission_Id int 
should be declared before the insert statement ..

Also as a best practise you should declare all the variables at the beginning of the stored procedure ..

Thanks,
Sivakumar.
Jun 9 '07 #2
cetpainfotech
15 Byte
This error in Microsoft SQL Server occurs when you reference a variable that has not been declared. To resolve this error, you need to declare the variable before you use it in your query.
Here's an example of how you can declare a variable in SQL Server:

DECLARE @variable_name data_type
SET @variable_name = value

Replace variable_name with the name you want to give to your variable, and data_type with the appropriate data type (e.g. INT, NVARCHAR, DATETIME, etc.). And value should be replaced with the actual value you want to assign to the variable.

Once you have declared the variable, you can use it in your query just like any other value. For example:
DECLARE @myVariable INT
SET @myVariable = 5
SELECT * FROM myTable WHERE myColumn = @myVariable

In this example, the variable @myVariable is declared as an INT and assigned the value 5. The variable is then used in the WHERE clause of the SELECT statement to filter the results based on the value of myColumn.

By declaring and using variables in this way, you can avoid the "Must declare the scalar variable" error and ensure that your queries run correctly in SQL Server

If you're looking to build your skills in Microsoft SQL , CETPA Infotech is the perfect place to start. With its comprehensive training programs, expert instructors, and hands-on approach to learning, CETPA Infotech is the ideal choice for anyone looking to take their career to the next level in the cloud computing industry.
Feb 10 '23 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

2
by: Rudy Ray Moore | last post by:
Whenever I get any error with Vc++7.1/.net/2003, it is followed by huge ammounts of "template assistance" error messaging referencing template code (MTL) that has nothing to do with the error. ...
3
by: Ken Adeniji | last post by:
Must declare the scalar variable '@FirstName' ContactGridViewWebForm.aspx <aspqlDataSource RunAt="server" ID="SqlDataSourceContact" ...
3
by: Cecil | last post by:
I get this error: Msg 137, Level 15, State 2, Line 2 Must declare the scalar variable "@DBName". W/ this code: --Constants DECLARE @DBName varchar(20); SET @DBName = 'Base';
2
by: Oded Dror | last post by:
Hi there, Please take a look at the source code and tell me whats wrong? Imports System.Data Imports System.Data.SqlClient Partial Class Test Inherits System.Web.UI.Page Const conString As...
2
by: shsandeep | last post by:
CREATE FUNCTION MYSCHEMA.FUNCTION1(SEQNAME VARCHAR(100)) RETURNS CHAR(100) LANGUAGE SQL MODIFIES SQL DATA ------------------------------------------------------------------------ -- SQL UDF...
1
by: AndrewD | last post by:
when the following SELECT is executed via A cursor to SQL 2005 it works SELECT * FROM LCTRY WHERE LANGUAGE = 'EN' AND CTRY_CODE = :CTRY BUT SELECT * FROM LCTRY WHERE CTRY_CODE = :CTRY...
3
by: ashokakr | last post by:
Hi all This my procedure, when i try to run the procedure it says "coitem_linenumber" is not a scalar variable. Can any one say what is the error and how i can correct it declare wotype...
4
by: Chronictank | last post by:
Hi, as a bit of background (and seeing as it is my first post :)) i am a complete newbie at perl. I literally picked it up a week ago to do this project as it seemed like the best choice for a...
1
by: Mark | last post by:
I am really struggling with this, trying to understand why it doesn't work. I've simplified the code down to the essentials. The GridView displays in ReadOnly mode just fine, Clicking the "edit"...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.