Is It Time To Stop Using IsNumeric()?

word image 51 Is It Time To Stop Using IsNumeric()?

SELECTDateString,

   Try_Parse(DateStringASdatetime2USING‘en-Uk’)AStryParse,

   Try_Convert(DATETIME2,DateString)ASTryConvert,

   Coalesce(

   Try_Convert(DATETIME2,DateString,0),  Try_Convert(DATETIME2,DateString,1),Try_Convert(DATETIME2,DateString,2),

   Try_Convert(DATETIME2,DateString,3),Try_Convert(DATETIME2,DateString,4),Try_Convert(DATETIME2,DateString,5),

   Try_Convert(DATETIME2,DateString,6),Try_Convert(DATETIME2,DateString,7),Try_Convert(DATETIME2,DateString,8),

   Try_Convert(DATETIME2,DateString,9),Try_Convert(DATETIME2,DateString,10),Try_Convert(DATETIME2,DateString,11),

   Try_Convert(DATETIME2,DateString,12),Try_Convert(DATETIME2,DateString,101),Try_Convert(DATETIME2,DateString,102),

   Try_Convert(DATETIME2,DateString,103),Try_Convert(DATETIME2,DateString,104),Try_Convert(DATETIME2,DateString,105),

   Try_Convert(DATETIME2,DateString,106),Try_Convert(DATETIME2,DateString,107),Try_Convert(DATETIME2,DateString,108),

   Try_Convert(DATETIME2,DateString,109),Try_Convert(DATETIME2,DateString,110),Try_Convert(DATETIME2,DateString,111),

   Try_Convert(DATETIME2,DateString,112),Try_Convert(DATETIME2,DateString,113),Try_Convert(DATETIME2,DateString,114),

   Try_Convert(DATETIME2,DateString,120),Try_Convert(DATETIME2,DateString,121),Try_Convert(DATETIME2,DateString,126),

   Try_Convert(DATETIME2,DateString,127),Try_Convert(DATETIME2,DateString,130))

From

(values(N‘Jun 23 2017  3:57PM’),(N’06/23/17′),(N‘17.06.23’),(’23/06/17′),(N‘23.06.17’),

  (N’23-06-17′),(N’23 Jun 17′),(N‘Jun 23, 17′),(N’15:57:54′),(N‘Jun 23 2017  3:57:54:810PM’),

  (N’06-23-17′),(N’17/06/23′),(N‘170623’),(N‘Jun 23 2017  3:57PM’),(N’06/23/2017′),

  (N‘2017.06.23’),(N’23/06/2017′),(N‘23.06.2017’),(N’23-06-2017′),(N’23 Jun 2017′),

  (N‘Jun 23, 2017′),(N’15:57:54′),(N‘Jun 23 2017  3:57:54:810PM’),(N’06-23-2017′),

  (N‘2017/06/23′),(N‘20170623’),(N’23 Jun 2017 15:57:54:810′),(N’15:57:54:810′),

  (N‘2017-06-23 15:57:54′),(N‘2017-06-23 15:57:54.810′),(N‘2017-06-23T15:57:54.810′),

  (N‘2017-06-23T15:57:54.810′),(N’29 رمضان 1438  3:57:54:810PM’)

)sample(dateString)

Let’s block ads! (Why?)

SQL – Simple Talk