HEELPBOOK - SQL Server 2005 - Determine datatype of variable ####################### ########## SCENARIO ############# Is it possible to determine the type of a local variable at runtime in TSQL? For example, say I wanted to do something along these lines: IF ( @value IS INTEGER ) Or IF ( TYPEOF(@value) = ) Does anyone know of any way to accomplish this? EDIT: This is not for a specific task, this is more of a general knowledge question. I do appreciate answers that indicate that the type should be known since it is declared within the same batch, I am curious as to whether the type can be determined at runtime. ############ SOLUTION ################### declare @d int select @d = 500 if cast(sql_variant_property(@d,'BaseType') as varchar(20)) = 'int' print 'yes' else print 'no' ############ ARTICLE INFO ############# Article Month: April Article Date: 18/04/2012 Permalink: http://heelpbook.altervista.org/2012/sql-server-2005-determine-datatype-of-variable/ Source: http://stackoverflow.com/questions/447944/sql-server-2005-determine-datatype-of-variable Language: English View more articles on: http://www.heelpbook.net/ Follow us on Facebook: http://it-it.facebook.com/pages/HeelpBook/100790870008832 Follow us on Twitter: https://twitter.com/#!/HeelpBook Follow us on RSS Feed: http://feeds.feedburner.com/Heelpbook Follow us on Delicious: http://delicious.com/heelpbook