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)
 Function with parameters as Variant data type

Author  Topic 

ivacacela
Starting Member

10 Posts

Posted - 2007-01-25 : 13:41:36
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 say

my_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)
as
begin
return cast(@param1 as varchar(100)) + ':' + cast(@param2 as varchar(100))
end

select dbo.TestVariant(123, getdate())
select dbo.TestVariant('hello', $300)
Go to Top of Page
   

- Advertisement -