Ion Lica
Ion Lica

Reputation: 21

How to correct this sql function

Create function GetDiffence (@difference float)
returns @Modify table
(Cod int, Pret float, Diferenta float)
as
begin
Insert @Modify
Select Cod, Pret, @difference-Pret as Diferenta
from PC_uri
order by Cod
Return
end

Select * from GetDiffence(350)

It's say that "create function must be the only statement in the batch sql". What is wrong here. I cant understand..... Its work fine but why i get this error,...

Upvotes: 0

Views: 45

Answers (1)

Evgeni Dimitrov
Evgeni Dimitrov

Reputation: 22496

You probably try to execute all that script at once. First create the function:

Create function GetDiffence (@difference float)
returns @Modify table
(Cod int, Pret float, Diferenta float)
as
begin
Insert @Modify
Select Cod, Pret, @difference-Pret as Diferenta
from PC_uri
order by Cod
Return
end

And than if it's successful you can try to call it:

Select * from GetDiffence(350)

Upvotes: 1

Related Questions