Site Sponsored By: SQLDSC - SQL Server Desired State Configuration
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.
Hi,I need some help to validate if with SQL Server 2005 is possible to write a function with the parameters as variant datatype, that is defined at run-time. I'm trying to put into a function a CASE WHEN THEN equivalent.Let's saymy_fun1(par1,par2,par3,par4)1st time: my_fun1("hello","h","a","b")2nd time: my_fun1(123,3,1,2)Best Regards,Ivan
snSQL
Master Smack Fu Yak Hacker
1837 Posts
Posted - 2007-01-25 : 13:57:35
Use the sql_variant data type, here's an example
create function TestVariant(@param1 sql_variant, @param2 sql_variant)returns varchar(200)asbegin return cast(@param1 as varchar(100)) + ':' + cast(@param2 as varchar(100))endselect dbo.TestVariant(123, getdate())select dbo.TestVariant('hello', $300)