用户自定义函数:
谁帮我看一下这一段代码的错误:
SET QUOTED_IDENTIFIER ON
GO
SET ANSI_NULLS ON
GO
ALTER function makeField(@FldName nvarchar(10),@FldType nvarchar(10),
@FldLen nvarchar(10), @FldDec nvarchar(10))
returns nvarchar(50) as begin
declare @result as nvarchar(50)
declare @FName nvarchar(10)
declare @FType nvarchar(10)
declare @FLen nvarchar(10)
declare @FDec nvarchar(10)
set @FName=ltrim(rtrim(isnull(@FldName,'')))
set @FType=ltrim(rtrim(isnull(@FldType,'')))
set @FLen =ltrim(rtrim(isnull(@FldLen,'')))
set @FDec =ltrim(rtrim(isnull(@FldDec,'')))
if @FName='' RAISERROR('字段名为空',16, 1)
if @FType='' RAISERROR ('字段'&@FldName&'类型为空',16, 1)
if @FType in ('varchar','char','nchar','nvarchar','decimal','numeric') and not isnumeric(@FLen) begin
RAISERROR ('字段'&@FName&'没有指定数据的长度',16, 1)
if cast(@FLen as int)<=0 RAISERROR ('数据' & @FName &'没有长度',16, 1)
end
if @FType in ('decimal','numeric') and not isnumeric(@FLen) begin
RAISERROR ('字段' & @FName &'没有指定小数位数',16, 1)
if cast(@FDec as int)<=0 RAISERROR ('字段' & @FName & '没有指定小数位数',16, 1)
end
set @result='['+isnull(@FName,'')+'] ' + isnull(@FType,'') + ' '
set @result=@result+
case
when isnull(@FType,'') in('varchar','char','nchar','nvarchar') then
'(' + isnull(@FLen,'') + ')'
when @FldType in('decimal','numeric') then
'(' + isnull(@FLen,'') + ',' + isnull(@FDec,'') + ')'
else
''
end
return @result + ',' + NCHAR(13)
End
GO
SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS ON
GO