Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2005 Forums
 Transact-SQL (2005)
 Using Constraint to control date value

Author  Topic 

wkm1925
Posting Yak Master

207 Posts

Posted - 2010-01-11 : 23:55:19
I've table as follow
declare @tMyData table
(
TrnxID int,
CardNo varchar(20),
CardExpired datetime
)

1. I want CardExpired Field only allow the 1st day of the month can be inserted.

How to create Contraint to control that?

senthil_nagore
Master Smack Fu Yak Hacker

1007 Posts

Posted - 2010-01-12 : 00:02:17
ALTER TABLE @tMyData WITH CHECK ADD CONSTRAINT CK_tMyData CHECK ((datepart(day,[CardExpired])=(1)))

ALTER TABLE @tMyData CHECK CONSTRAINT CK_tMyData

Senthil.C
------------------------------------------------------
[Microsoft][ODBC SQL Server Driver]Operation canceled

http://senthilnagore.blogspot.com/
Go to Top of Page

wkm1925
Posting Yak Master

207 Posts

Posted - 2010-01-12 : 00:06:55
tq very much
Go to Top of Page

senthil_nagore
Master Smack Fu Yak Hacker

1007 Posts

Posted - 2010-01-12 : 00:15:14
Welcome :)

Senthil.C
------------------------------------------------------
[Microsoft][ODBC SQL Server Driver]Operation canceled

http://senthilnagore.blogspot.com/
Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2010-01-12 : 01:38:07
quote:
Originally posted by senthil_nagore

ALTER TABLE @tMyData WITH CHECK ADD CONSTRAINT CK_tMyData CHECK ((datepart(day,[CardExpired])=(1)))

ALTER TABLE @tMyData CHECK CONSTRAINT CK_tMyData

Senthil.C
------------------------------------------------------
[Microsoft][ODBC SQL Server Driver]Operation canceled

http://senthilnagore.blogspot.com/



You can only alter permanent/temporary table not the table variable

Madhivanan

Failing to plan is Planning to fail
Go to Top of Page
   

- Advertisement -