Shweta
Well-known Member
- Joined
- Jun 5, 2011
- Messages
- 514
Hi All,
I have two tables "student" & "student_add" in SQL. I have created a procedure to update the address of a student. While executing the procedure I am getting an error : Must declare the scalar variable "@s_name".
Table: Student
<tbody>
</tbody>
Table: student_add
<tbody>
</tbody>
Procedure:
Instead of declaring the variables, if I pass the values(name and address) directly to the procedure like below, it works fine.
Kindly suggest.
Thanks in advance!
Regards,
Shweta Jain
I have two tables "student" & "student_add" in SQL. I have created a procedure to update the address of a student. While executing the procedure I am getting an error : Must declare the scalar variable "@s_name".
Table: Student
Student_Name | Roll_No |
Deepti | 40 |
Priya | 30 |
Shivya | 50 |
Shweta | 10 |
Yuvraj | 20 |
<tbody>
</tbody>
Table: student_add
Roll_No | Stu_Address |
10 | Noida |
20 | Gurgaon |
30 | Ghaziabad |
40 | Delhi |
50 | Faridabad |
<tbody>
</tbody>
Procedure:
Code:
Create proc Update_address
@Student_Name nvarchar(20),@Student_address nvarchar(20)
as
begin
update student_add
set Stu_Address = @Student_address
where Roll_No = (select Student_add.roll_no
from student_add
inner join student
on student.roll_no = student_add.roll_no
where student.student_name = @Student_Name)
end
----Executing the procedure
declare @s_name nvarchar(20) = 'Deepti'
declare @s_address nvarchar(20)='Gwalior'
execute update_address @s_name,@s_address ----prompting an error
[COLOR=#ff0000]Msg 137, Level 15, State 2, Line 2[/COLOR]
[COLOR=#ff0000]Must declare the scalar variable "@s_name".[/COLOR]
Instead of declaring the variables, if I pass the values(name and address) directly to the procedure like below, it works fine.
Code:
execute update_address 'Deepti','Gwalior'
Kindly suggest.
Thanks in advance!
Regards,
Shweta Jain
Last edited: