Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 Strange error

Author  Topic 

MAGI System
Starting Member

2 Posts

Posted - 2010-10-07 : 04:30:22
Hi,
I'm new to sql server programming and i need your help for a problem very strange (for me, but for you i don't think).

I have this code


ALTER FUNCTION [dbo].[GetQtaAttuale](@DTFTS int, @DATAINI int, @DATAFIN int, @TPRGS varchar(10), @CDRIS varchar(1), @QTSPR float, @UNMIS varchar(10), @PESUN float)
RETURNS float
BEGIN


declare @return_value float
set @return_value = 0

if (@PESUN IS NULL)
begin

end

return @return_value

END


Sql Management 2008 say me that the line with "return @return_value" was in error.
If I delete the if statement everything work, but.. why?
I have a lot of other function similar to this with if and other statement with no error.

Thank you for your patience

pk_bohra
Master Smack Fu Yak Hacker

1182 Posts

Posted - 2010-10-07 : 04:41:54
quote:
Originally posted by MAGI System

Hi,
I'm new to sql server programming and i need your help for a problem very strange (for me, but for you i don't think).

I have this code


ALTER FUNCTION [dbo].[GetQtaAttuale](@DTFTS int, @DATAINI int, @DATAFIN int, @TPRGS varchar(10), @CDRIS varchar(1), @QTSPR float, @UNMIS varchar(10), @PESUN float)
RETURNS float
BEGIN


declare @return_value float
set @return_value = 0

if (@PESUN IS NULL)
begin

end

return @return_value

END


Sql Management 2008 say me that the line with "return @return_value" was in error.
If I delete the if statement everything work, but.. why?
I have a lot of other function similar to this with if and other statement with no error.

Thank you for your patience



A BEGIN and END statement block must contain at least one Transact-SQL statement.

CheckHere
Go to Top of Page

MAGI System
Starting Member

2 Posts

Posted - 2010-10-07 : 05:02:27
Thank you very much.
So, Sql Managemet say the error during writing.. I need more study of this platform ^^

Can i ask another thing?
In the if statemens, a code like this
[CODE]
if (@DTFTS > = @DATAINI & @DTFTS <= @DATAFIN)
begin
... my code ...
end
[/CODE]

is not correct, why?
Go to Top of Page

harsh_athalye
Master Smack Fu Yak Hacker

5581 Posts

Posted - 2010-10-07 : 05:17:33
Change IF to:


if (@DTFTS > = @DATAINI and @DTFTS <= @DATAFIN)




Harsh Athalye
http://www.letsgeek.net/
Go to Top of Page

Sachin.Nand

2937 Posts

Posted - 2010-10-07 : 06:43:22
There is no need for begin & end clauses.This will work

if (@DTFTS > = @DATAINI and @DTFTS <= @DATAFIN)
... my code ...
return @return_value




PBUH

Go to Top of Page

pk_bohra
Master Smack Fu Yak Hacker

1182 Posts

Posted - 2010-10-07 : 06:53:19
quote:
Originally posted by Sachin.Nand

There is no need for begin & end clauses.This will work

if (@DTFTS > = @DATAINI and @DTFTS <= @DATAFIN)
... my code ...
return @return_value




PBUH





For single T-sql statement the block is not required but if you have more than 1 T-SQL statement then Begin and End block is required.
Go to Top of Page

DonAtWork
Master Smack Fu Yak Hacker

2167 Posts

Posted - 2010-10-07 : 07:02:58
Also, RETURN will only return an INTEGER value, and you have your variable declared as a FLOAT.

http://weblogs.sqlteam.com/jeffs/archive/2008/05/13/question-needed-not-answer.aspx
How to ask: http://weblogs.sqlteam.com/brettk/archive/2005/05/25/5276.aspx

For ultra basic questions, follow these links.
http://www.sql-tutorial.net/
http://www.firstsql.com/tutor.htm
http://www.w3schools.com/sql/default.asp
Go to Top of Page

Sachin.Nand

2937 Posts

Posted - 2010-10-07 : 07:11:46
[code]
CREATE FUNCTION [dbo].[GetQtaAttuale]()
RETURNS int
BEGIN


declare @return_value float
set @return_value = 0
declare @PESUN int=NULL


if (@PESUN IS NULL)
set @return_value=1
else
set @return_value=2

return @return_value

END

GO

select dbo.[GetQtaAttuale]()

[/code]

PBUH

Go to Top of Page
   

- Advertisement -