Quantcast
Channel: Forum Getting started with SQL Server
Viewing all articles
Browse latest Browse all 7129

Simple function

$
0
0

I am using 2008 R2, which apparently doesn't include the IIF function, so I am trying to create one, partly because it's useful, and partly to learn the syntax in SQL Server.  I am getting several errors.  Can someone please troubleshoot this?  Thanks.

CREATE FUNCTION IIF(@A SQL_Variant, @B SQL_Variant, @C SQL_Variant)
RETURNS SQL_Variant
AS
BEGIN
	DECLARE @ResultVar SQL_Variant
		CASE 
			WHEN @A=1 Then
				Set @ResultVar=@B
			ELSE
				Set @ResultVar=@C
		END
	RETURN @ResultVar
END
GO


b


Viewing all articles
Browse latest Browse all 7129

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>