Tuesday, November 2, 2010

check constraint for TimeToReach

create table rsc_check_constraint_test(
TimeToReach
ID int IDENTITY(1,1) , nvarchar(10) CHECK ( LEN(TimeToReach) = 5 AND SUBSTRING(TimeToReach , 3,1) = ':' AND ISNUMERIC(SUBSTRING(TimeToReach, 1,2)) = 1 AND ISNUMERIC(SUBSTRING(TimeToReach, 4,2)) = 1 AND CONVERT(int , SUBSTRING(TimeToReach , 1,2)) > 5 AND CONVERT(int , SUBSTRING(TimeToReach , 1,2)) < 19 )
)




insert
 select
 drop table rsc_check_constraint_test
* from rsc_check_constraint_test
rsc_check_constraint_test values ('19:14')

No comments:

Post a Comment