In SQL Server 2005 R2, I want to select:
IF column_1 IS NULL THEN MyUserDefinedFunction_2(column_2) ELSE MyUserDefinedFunction_1(column_1)
Any suggestions on how to achieve this would be greatly appreciated.
There are several types of user defined functions based on the data they return. If both functions are "Scalar Valued Functions", then you should be able to do this:
Code:
Select ColumnA,
ColumnB,
Case When Column_1 Is NULL
Then dbo.MyUserDefinedFunction_2(column_2)
Else dbo.MyUserDefinedFunction_1(column_1)
End As ColumnNameAlias
From YourTableNameHere
-George
Microsoft SQL Server MVP My Blogs SQLCop twitter
"The great things about standards is that there are so many to choose from." - Fortune Cookie Wisdom
SELECT
CASE WHEN dbo.tbArcStudies.gStudienr IS NULL
THEN 'p'+dbo.udf_FormatProjectNumber(dbo.tbArcStudies.gProjnr)
ELSE dbo.udf_FormatStudyNumber(dbo.tbArcStudies.gStudienr)
END
FROM dbo.tbArcStudies
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.