1
I have a Function that returns the status of a request (in the database is as int) that only has two possible values, 0 (inactive), 1 (active). I was trying to increment it with 'case when' in case the result is 0 she returns to me 'Inactive Request' or if the result is 1 she returns to me 'Active Request'. Down with my Function:
create function NumPedidoStatus(@cod int)
returns int
as
begin
declare @Retorno int
set @Retorno=(select status from pedido where idPedido = @cod)
return @Retorno
end
What I tried to do was take the return value and use it in 'case when', only I constantly found several errors and could not do as I described above.
It turned out that I could not do and I wish someone could help me what I should modify in this Function so that it operates the way I wish.
NOTE: I am using SQL SERVER
what mistake you’re making?
– Marco Souza
I had several mistakes and I wrote down almost nothing, but there was one that I remember that occurred more than once. It was "create Function must be the only statement in the batch". But I believe that I was not able to insert the case when correctly, this I think was the big problem.
– DiChrist
The relation in your table request returns one to one in the
where idPedido = @cod
– Marco Souza