Dana Stevens

Ruminations of a software developer.
posts - 8, comments - 370, trackbacks - 0

Wednesday, August 13, 2008

SQL Quick Tip - Determine data type of column.

Use the very nifty SQL_VARIANT_PROPERTY to determine the data type of a returned column.  
Admittedly, it’s faster to look at the table definition in SSMS.  But this is pretty neat.
 
DECLARE @TableVar TABLE (MyColumn numeric(18,5)) 

INSERT INTO @TableVar VALUES (5.5) 

SELECT TOP 1 
     MyColumn, 
     SQL_VARIANT_PROPERTY(MyColumn, 'BaseType') AS 'Base_Type', 
     SQL_VARIANT_PROPERTY(MyColumn, 'Precision') AS 'Precision', 
     SQL_VARIANT_PROPERTY(MyColumn, 'Scale') AS 'Scale' 
FROM @TableVar 

posted @ Wednesday, August 13, 2008 12:03 AM | Feedback (25) |

Powered by:
Powered By Subtext Powered By ASP.NET