Incorrect syntax near the keyword As

I opened a 'New Query' window in SSMS. I pasted the following code (well this is a simplified version but throws the same error as the real version).

Create function dbo.GetFull (@dbName varchar(100))
Returns double
As  --   <------------- underlined in red. 
Begin
	Declare @PercentFull double
	select @PercentFull = 0
	
	Return @PercentFull
End 
go

March 13th, 2014 3:58am

Seems I can avoid the syntax error by switching to decimal.  What's wrong with double?

Free Windows Admin Tool Kit Click here and download it now
March 13th, 2014 4:02am

Oh I guess in Tsql it's called 'float'...
March 13th, 2014 4:03am

"Double" isn't a valid Transact-SQL data type, you have to use a different one, see Data Types (Transact-SQL)

Free Windows Admin Tool Kit Click here and download it now
March 13th, 2014 4:04am

In T-SQl float and real represent approximate numerics 

Whereas Decimal and Numeric represent exact numeric data with predefined precision and scale values

March 13th, 2014 4:08am

Try

Create function dbo.GetFull (@dbName varchar(100))
Returns double
WITH EXECUTE AS CALLER
As
Begin
	Declare @PercentFull double
	select @PercentFull = 0
	
	Return @PercentFull
End 
go

Free Windows Admin Tool Kit Click here and download it now
March 13th, 2014 4:09am

Try

Create function dbo.GetFull (@dbName varchar(100))
Returns double
WITH EXECUTE AS CALLER
As
Begin
	Declare @PercentFull double
	select @PercentFull = 0
	
	Return @PercentFull
End 
go
March 13th, 2014 4:48am

This topic is archived. No further replies will be accepted.

Other recent topics Other recent topics