0

What's wrong with this code?

CREATE PROCEDURE Proc
( 
     @factura_id int, @produs_id int, @pret float, @cantitate int,@nr_ordine int
)
as
--declare @factura_id int, @produs_id int, @nr_ordine int, @pret float,  @cantitate int
begin
    if(((select COUNT (id_produs) from Produse where id_produs=@produs_id)=1))
        insert into FacturaProdus(id_factura,id_produs,pret,cantitate,nr_ordine) 
        values(@factura_id,@produs_id,@pret, CONCAT ('-',convert(float,@cantitate),@nr_ordine))
    else
    begin
        print 'hei'
    end
end

I can't find a solution for this.When i execute it, it gives me:

Msg 156, Level 15, State 1, Line 1
Incorrect syntax near the keyword 'Proc'.
Msg 137, Level 15, State 2, Line 8
Must declare the scalar variable "@produs_id".
Msg 137, Level 15, State 2, Line 9
Must declare the scalar variable "@factura_id".

What to do?

1 Answer 1

3

Proc is reserved word in SQL server (I assume you're using it based on syntax and error messages).

So if you really want to create procedure having such a name (I recommend you to choose another name, though) - enclose it into square brackets:

CREATE PROCEDURE [Proc]
(
 .....
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.