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 2000 Forums
 SQL Server Development (2000)
 Data types with input variables

Author  Topic 

AskSQLTeam
Ask SQLTeam Question

0 Posts

Posted - 2002-07-11 : 09:15:14
Paul writes "Here is my question, we have a stored procedure in SQL 2000 that has 3 simple input variables. Suppose one of those input parameters is for a column that we don't know the datatype for. Is it possible in the stored procedure to declare the parameter name, and assign it the datatype of a particular column? For example:

Create Procedure sp_MyProc
@SomeVar int,
@SomeOtherVar int,
@UnknownDataTypeVar ?????
AS
/* Do funky stuff here */
GO

It's not difficult to get the datatype of the column using the SQL_VARIANT_PROPERTY function, but there has to be a better way! We have tried some different stuff using the database name, owner name, table name, column name and stuff, but to no sucess. We have examples of it done in Oracle, but MSSQL isn't oracle of course. Have you ever seen it done?"

macka
Posting Yak Master

162 Posts

Posted - 2002-07-11 : 09:33:17
Since SQL2000 you can declare a column as type sql_variant - I think you can declare a parameter as this type too.

So something like this may work (I haven't tested it mind you!)

Create Procedure sp_MyProc
@SomeVar int,
@SomeOtherVar int,
@UnknownDataTypeVar sql_variant
AS
/* Do funky stuff here */


macka.

Go to Top of Page
   

- Advertisement -