declare
@sid int,@sname varchar(20),@s1 int,@s2 int,@s3 int,@totalmarks int,@avg float,
@grade1 char(1),@grade2 char(1),@grade3 char(1),@percentage float,@actualmarks int
begin
set @sid=487
set @sname='venkat'
set @s1=100
set @s2=85
set @s3=55
set @totalmarks=@s1+@s2+@s3
set @avg=@totalmarks/3
set @percentage=cast(@totalmarks /(@actualmarks*100) as float
set @grade1='a'
set @grade2='b'
set @grade3='c'
if(@percentage <55)
begin
print @grade3
end
if(@percentage >=55 or @percentage <=75)
begin
print @grade2
end
if(@percentage >75)
begin
print @grade1
end
print @sid
print @sname
print @totalmarks
print @avg
print @percentage
end
I AM UNABLE TO PRINT PERCENTAGE
IT IS SHOWING Must declare the scalar variable "@percentage".
AND I NEED TO PRINT GRADE ALSO BASED ON PERCENTAGE
I AM UNABLE TO DO IT PLEASE HELP ME
Muhammad Imran AnsariPosted Oct 22, 2022, 1:31 PM
Hi Jaya,
You need to check the following in your script to run as expectations:
1. Set @actualmarks value
2. Change your percentage formula as below:
3. Change the datatype of @totalmarks and @actualmarks as float instead of int and use the below formula: (Suggestions)
4. In your send IF condition use AND instead of OR like: because you are checking the average between 55 to 75