Community blog feed
SQL_VARIANT_PROPERTY function
- 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)
Related blog entries
-
Fun with GO
by Madhivanan
-
Should alias names be preceded by AS? - Part 2
by Madhivanan
-
Splitting delimited data to columns - Set based approach
by Madhivanan
-
Return TOP N rows
by Madhivanan
-
Export to EXCEL with column names
by Madhivanan