views:

40

answers:

3

Is there any in built functions in SQL server to find whether the given value is integer or currency or date or decimal?

+1  A: 

Well there is ISDATE() and ISNUMERIC(). What do you need to do?

Hogan
I want the in built functions to find int, currency and decimal.
susanthosh
Paste some sample code, we can't work out what you want.
Codesleuth
A: 

If you're dealing with an SQL_VARIANT, use the built-in SQL_VARIANT_PROPERTY function:

SELECT   SQL_VARIANT_PROPERTY(@value,'BaseType') AS 'Base Type'
Codesleuth
A: 

There are no real inbuilt functions like you are looking for. The only option to determine is to query sysobjects, syscolumns and systypes (SQL 2000).

select
    obj.name,
    col.name,
    typ.name
From dbo.sysobjects obj
    Inner Join dbo.syscolumns col
        On col.id = obj.id
    Inner Join dbo.systypes typ
        On typ.xusertype = col.xusertype

This query will list all tables with their columns and their types. Currency will be of type money, decimal is numeric. Within the columns table you can find the precision and scale of numeric.

-1 for false statement, +1 for very useful answer. There are functions that does what he is looking for, as I stated in my answer. They just might not do everything he is looking for -- then your answer can help in a non-standard way.
Hogan
IsDate I definitely have overseen, but please can you enlighten how IsNumeric is able to differentiate between a numeric, money and integer type?This is the original question and therefore I made the addition "...like you are looking for" as there is no function to do IsMoney, IsInteger or IsNumeric (sensing the numeric type only instead of verifying a number).
But this will not look at data in a varchar field and tell you if is an integer. That is what most people asking this sort of question want to be able to do.
HLGEM