tags:

views:

22

answers:

1

Table1

Time

10:00:00
12:00:00
Absent
14:00:00
Holiday
...,

Time column Datatype is varchar

I want to check the time column value is numeric then 'Present'

Tried Query

Select case when isnumeric(time) then 'Present' else time end as time from table1

Showing error in 'then'

How to modify my query according to my requirement

Need Query Help

+2  A: 

Try using ISDATE

Returns 1 if the expression is a valid date, time, or datetime value; otherwise, 0.

Something like

DECLARE @Table TABLE(
    [Time] VARCHAR(50)
)

INSERT INTO @Table SELECT '10:00:00' 
INSERT INTO @Table SELECT '12:00:00' 
INSERT INTO @Table SELECT 'Absent' 
INSERT INTO @Table SELECT '14:00:00' 
INSERT INTO @Table SELECT 'Holiday'

SELECT  *,
        ISDATE(Time),
        case when ISDATE(time) != 0 then 'Present' else time end
FROM    @Table
astander
+1 good example code!
KM