Jump to content

Qual o erro neste exercício?


Arkangel
 Share

Recommended Posts

Boas pessoal. Estava aqui a resolver uns exercícios em sql, onde tenho de descobrir o(s) erro(s). Mas encalhei aqui num. Conseguem saber o que está mal neste código?

DECLARE @Current_Month int
SELECT @Current_Month = CURRENT_MONTH FROM RD_PROPERTIES 
IF @@ERROR<>0 
Begin
EXEC SP_LOG_ERROR @@ERROR, 'Error while getting the CURRENT_MONTH'
GOTO EndProc
End
RETURN (0)
EndProc:
RETURN (-1)

Obrigado 😉.

Link to comment
Share on other sites

A lógica..parece-me devia ser...

Se ele encontrar erro...retornar X

Caso contrário retornar Y...

Parece-me que deveria ser essa a lógica da função...

Mas tal como referi anteriormente o plsql tem muitas diferenças... e não percebo sequer nada do tratamento de erros do SQL Server..

Quando te pedirem peixe.... ensina-os a Pescar!!Hum..lálálálá!!

Link to comment
Share on other sites

Ainda n tive oportunidade de testar isto no sql server 2000 pq n tive tempo, mas se @@error for diferente de zero, vai executar akilo k está dentro e passar para o endproc. Isso significaria que iria retornar 0... e 1. já k se for diferente de 0, retorna 0 pq n está dentro da clausula else... mas tb retorna 1 por causa da execução dentro do begin k dps apontará para o endproc. Se calhar é este o erro...

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...

Important Information

By using this site you accept our Terms of Use and Privacy Policy. We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.