October 31, 2007 at 7:31 am
Does anyone know of a function which will return the data type of a selection i.e.
declare @somevariable int
set @somevariable = 1
select someFunction(@somevariable)
output -- integer -- for example
October 31, 2007 at 7:45 am
somefunction is typed, so at the moment you specify a parameter, the parameter is cast to the type the function accepts.
Are you trying to get the data type of a variable? or a table column (in which case you can explore the system views)
Regards,
Andras
October 31, 2007 at 7:49 am
You may also want to look at the SQL_VARIANT_PROPERTY. Not the nicest solution :), but:
select SQL_VARIANT_PROPERTY ( cast (1 as int) , 'BaseType ' )
gives you back int 🙂
Regards,
Andras
October 31, 2007 at 7:56 am
Look at the schema information view
SELECT * FROM information_schema.columns
should help you get what you are after.
October 31, 2007 at 8:02 am
Andras Belokosztolszki (10/31/2007)
You may also want to look at the SQL_VARIANT_PROPERTY. Not the nicest solution :), but:
Just be aware the table must have data in it to produce an output and that it will produce a row for each row unless you use TOP 1 to only handle one. As well, the output will be null if the columns value is null in the row being looked at.
October 31, 2007 at 8:08 am
Antares686 (10/31/2007)
Andras Belokosztolszki (10/31/2007)
You may also want to look at the SQL_VARIANT_PROPERTY. Not the nicest solution :), but:Just be aware the table must have data in it to produce an output and that it will produce a row for each row unless you use TOP 1 to only handle one. As well, the output will be null if the columns value is null in the row being looked at.
This is true. The only place I'd use it would be in case of variables and sql_variants (as in the original post by Mark). table/view columns the system views are obviously preferred: the information schema as you mentioned, and sys.columns, sys.parameters (on 2005, 2008) and syscolumns on 2000.
Regards,
Andras
Viewing 6 posts - 1 through 5 (of 5 total)
You must be logged in to reply to this topic. Login to reply