Click here to Skip to main content
15,920,217 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
SQL
create or replace function givegrade(p in number) return char is g char(15);
 begin
    if p >= 70 then
            g:='Distinction';

            return g;
    elsif p >= 60 then
            g:='First';
            return g;
    elsif p>= 50 then
            g:='Pass';
            return g;
    else
            g:='Fail';
            return g;
    end if;
 end;



error given
======================
Msg 156, Level 15, State 1, Line 1
Incorrect syntax near the keyword 'or'.
Msg 156, Level 15, State 1, Line 3
Incorrect syntax near the keyword 'then'.
Msg 178, Level 15, State 1, Line 6
A RETURN statement with a return value cannot be used in this context.
Msg 132, Level 15, State 1, Line 8
The label 'g' has already been declared. Label names must be unique within a query batch or stored procedure.
Msg 178, Level 15, State 1, Line 9
A RETURN statement with a return value cannot be used in this context.
Msg 132, Level 15, State 1, Line 11
The label 'g' has already been declared. Label names must be unique within a query batch or stored procedure.
Msg 178, Level 15, State 1, Line 12
A RETURN statement with a return value cannot be used in this context.
Msg 132, Level 15, State 1, Line 14
The label 'g' has already been declared. Label names must be unique within a query batch or stored procedure.
Msg 178, Level 15, State 1, Line 15
A RETURN statement with a return value cannot be used in this context.
Posted
Comments
Tomas Takac 9-Jan-15 4:46am    
This looks like Oracle syntax. This will not work in SQL server of course. You need to rewrite it.
krishna97 9-Jan-15 4:54am    
how can used this query from sql server

1 solution

"how can used this query from sql server"

You can't.
SQL Server function syntax is different from Oracle: so you would need to rewrite it for SQL.

And since it is your homework, I'm not about to do it for you!
Stop grabbing code fragments at random from the internet, and start looking at your course documentation. You should be able to do this yourself - or your tutor would not have set it - so sit down and work it out. If you don;t do this yourself, then next weeks task is going to be even harder as it will assume that you know this stuff...
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900