Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Simple Function - New User 1

Status
Not open for further replies.

SaturnSeven

Programmer
Aug 4, 2005
40
GB
I'm a new user to SQL

I need a function that simply returns a sigle letter status depending the value passed to function.

I have writen the fuction below, but I get this message:-
Msg 102, Level 15, State 1, Procedure fn_ABCD, Line 12
Incorrect syntax near '@fn_ABCD'.

Can anyone help/point me in the right direction
Many thanks

USE DataWarehouse
go

IF EXISTS (SELECT *
FROM sysobjects
WHERE name = 'fn_ABCD')
DROP FUNCTION fn_ABCD
go

CREATE FUNCTION fn_ABCD(@Value int)
RETURNS nvarchar(1)

AS
BEGIN

DECLARE @fn_ABCD nvarchar(1)

IF @Value > 1000
@fn_ABCD = "A"
Else @Value > 200 and < 999
@fn_ABCD = "D"

RETURN (@fn_ABCD)
END
 
Code:
IF @Value > 1000
    set @fn_ABCD = 'A'
Else
 if @Value > 200 and @Value< 999
    set @fn_ABCD = 'D'
The varchar is an unnecessary overhead if the size is 1.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top