Community blog feed

SQL_VARIANT_PROPERTY function

Website
Blog
All about SQL Server
Posted
01 Nov 2008 at 09:47

Summary

If you want to know the datatype or length of a column , you can query on the system table syscolumns or system view INFORMATION_SCHEMA.COLUMNS But you dont need to query on system objects if you use SQL_VARIANT_PROPERTY function Example SELECT TOP 1 SQL_VARIANT_PROPERTY ( 'column_name' , 'basetype'

Post extract

If you want to know the datatype or length of a column , you can query on the system table syscolumns or system view INFORMATION_SCHEMA.COLUMNS But you dont need to query on system objects if you use SQL_VARIANT_PROPERTY function Example SELECT TOP 1 SQL_VARIANT_PROPERTY ( 'column_name' , 'basetype' ) FROM table_name which gives you the datatype of the column_name This is an example from Northwind .. Orders table SELECT TOP 1 SQL_VARIANT_PROPERTY ( 'orderid' , 'basetype' ) as basetype , SQL_VARIANT_PROPERTY...(read more)

We'd love to hear what you think! Submit ideas or give us feedback