I Have a table called Sur_Data and the data looks like:
ID SV_Date
258 13/01/2010
569 15/02/2011
695 26/05/2010
745 12/06/2010
Now I want to select the ID’s from that table and insert into another table so we are using something like:
Insert into Surdate(ID)
Select ID from Sur_Data
where ISDATE(SV_Date) = 1
Since the format in SV_Date is different it is not inserting any records into Surdate table.
So I am trying to see is there a way that we could restrict the data in Sur_Data table to have only date’s that are in MM/DD/YYYY format.So whenever they try to insert records of different format it should throw an error.
Can anyone help on this?
Edit: for example 2 & 3, ANSI WARNINGS must be off.
IS_DATEfunction is influenced byDATEFORMATsetting for current SQL Server session/connection.Example 1:
Results:
Now, you can see how
DATEFORMATinfluencesISDATEfunction.Instead of
ISDATEfunction you can useCONVERTfunction with different date/time styles. If a[n][var]charvalue doesn’t have the selected style thenCONVERTfunction will return NULL. Fordd/mm/yyyyvalues (british) can be used style 103 and formm/dd/yyyyvalues (U.S.) can be used style 101.Example 2:
Results:
Now, if you want to check SV_Date values for
mm/dd/yyyyformat (style 101 – U.S.) then you can use aCHECKconstraint like this:Example 3:
Results:
Observations:
If you want to find current
DATEFORMATsetting (current session) then you can usesys.dm_exec_sessionsview: