How to get sql_variant parameter for SQL CLR stored procedure?

How to add sql_variant parameter to SQL CLR stored procedure? Using System.Object does not work, and I do not see any attributes that I can use.

[Microsoft.SqlServer.Server.SqlProcedure]
public static void ClearOnePartition(
    SqlString aString
    , /* I want this to be a sql_variant */ object aVariant
)
{
    //do stuff here
}
+5
source share
2 answers

In Displaying CLR Parameter Data from SQL Books Online , Object is listed as the correct type to display sql_variant .

I created a simple SQL Server project and added the following class to it:

public partial class StoredProcedures
{
    [Microsoft.SqlServer.Server.SqlProcedure]
    public static void StoredProcedure1(object param1)
    {
        // Put your code here
        //Trace.Write(param1);
        SqlContext.Pipe.Send(param1.ToString());

    }
};

Then I modified the test.sql file to implement this saved process:

DECLARE @thing sql_variant = 'hahahahaha';

EXEC dbo.StoredProcedure1 @thing

:

hahahahaha

.

( 0 ())

sp_executesql.

+3

, CREATE PARTITION FUNCTION, :

, , ntext, image, xml, timestamp, varchar (max), nvarchar (max), varbinary (max), CLR .

sys.partition_parameters.

sys.partition_range_values ​​, value SQL_VARIANT ( , ).

, SQL_VARIANT ( ) object .NET.

NULL, DBNull.Value.

( SQL_VARIANT/object), GetType():

if (aVariant.GetType() == typeof(SqlInt16))
+1

All Articles