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 2005 Forums
 Transact-SQL (2005)
 Trying to call UDF inside a Case stmt

Author  Topic 

MyronCope
Starting Member

46 Posts

Posted - 2011-01-27 : 11:33:37
using sql server 2005:
I created a UDF that returns a table.

When I call this UDF using no case statement it works well but
however when I call a UDF inside of a case statement, I am getting the following errors
<ERROR>
Msg 156, Level 15, State 1, Line 7
Incorrect syntax near the keyword 'SELECT'.
Msg 156, Level 15, State 1, Line 9
Incorrect syntax near the keyword 'FROM'.
</ERROR>

The code I'm trying to use follows:
[code]
SELECT myValue,
CASE myCode
WHEN 'C' THEN
SELECT * FROM dbo.fcn_myUDF1(myValue)
END
FROM myTable WHERE ID = '123456'
GO
[/code

nigelrivett
Master Smack Fu Yak Hacker

3385 Posts

Posted - 2011-01-27 : 11:57:41
A case statement returns a value not a resultset.
try
SELECT myValue,
CASE myCode
WHEN 'C' THEN
(SELECT top 1 col1 FROM dbo.fcn_myUDF1(myValue))
END
FROM myTable WHERE ID = '123456'
GO


==========================================
Cursors are useful if you don't know sql.
SSIS can be used in a similar way.
Beer is not cold and it isn't fizzy.
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2011-01-27 : 12:45:21
can you elaborate on what udf returns?

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page
   

- Advertisement -