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
 SQL Server 2000 Forums
 Transact-SQL (2000)
 WHEN statement and issue with >

Author  Topic 

Tethys
Starting Member

3 Posts

Posted - 2005-11-08 : 17:44:34
Hi folks. I've an issue with a section of code that to my knowledge should work. Was hoping for feedback and any suggestions. Thank you in advance for any input

The user defined function is rather straight forward so here goes (and the error will be stated below code block with the errors in the code highlighted red.

-- User Defined Function --

CREATE  FUNCTION udf_RankDet(@ManagementHierarchy_ID INT)
RETURNS @FCIRank Table
(
FCI_Rank varchar(20)
)

AS
BEGIN

INSERT INTO @FCIRank(FCI_Rank)
SELECT CASE (Fac.MRRCost + Fac.MRRHFuture)
WHEN 0 THEN
CASE CAST(Fac.CRV AS FLOAT (2))
WHEN 0 THEN 'N/A'
WHEN > 0 THEN 'N/A'
WHEN < 0 THEN 'N/C'
ELSE 'N/C'
END
WHEN > 0 THEN
CASE CAST(Fac.CRV AS FLOAT (2))
WHEN 0 THEN 'Acceptable'
WHEN > 0 THEN
IF Fac.CRV >= 0.0 AND Fac.CRV <= 0.04
THEN 'Acceptable'
ELSE IF Fac.CRV > 0.04 AND Fac.CRV <= 0.09
THEN 'Good'
ELSE IF Fac.CRV > 0.09 AND Fac.CRV <= 0.14
THEN 'Fair'
ELSE IF Fac.CRV > 0.14 THEN 'Poor'
ELSE 'N/A'
WHEN < 0 THEN 'N/A'
ELSE 'N/A'
END
WHEN < 0 THEN 'N/A'
ELSE 'N/A'
END
FROM tblFacility Fac
WHERE Fac.ManagementHierarchy_ID = @ManagementHierarchy_ID

RETURN
END


******************
Error list:
1) Error 170: Incorrect Syntax near '>'
2) Incorrect syntax near keyword 'THEN'

******************

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2005-11-08 : 18:09:00
You can't put IF statements in the SELECT. Those will need to be converted to CASE statements.

Tara Kizer
Go to Top of Page

Tethys
Starting Member

3 Posts

Posted - 2005-11-08 : 18:56:34
Thanks for the input Tara. You were corret and I needed to turn the additional WHEN's into CASE statements. Data pulled correctly. =)
Go to Top of Page
   

- Advertisement -