unable to understand code

Hi Experts

I'm trying to understand the below code specially ElSE part but no luck. If somebody explain it then I really appreciate it. Thanks

WHEN LOAD_DATE = 9999-12-31 THEN NULL

--Convert date to smart surrogate INT of form YYYYMMDD

ELSE CONVERT(INT, (CONVERT(NVARCHAR(8), LOAD_DATE, 112)))

END AS LoadDateID --Alias using friendly name

Regards

Muz

April 11th, 2014 3:05am

If Load date is 9999-12-31 then return null. Otherwise it returns Load date as an integer. For instance, if the date is 2014/04/03, then it returns the number 20140403, and
Free Windows Admin Tool Kit Click here and download it now
April 11th, 2014 3:12am

but what is the meaning of 112 ?. Can you please explain it in more details. Thanks in advance
April 11th, 2014 3:15am

Hi ,

The else part simply converts the Date to Number format . it would be in YYYYMMDD format for eg. Todays date would look like 20140411 . This is a common requirement in data warehouse application to convert date to Number format which is also an ISO format.

Free Windows Admin Tool Kit Click here and download it now
April 11th, 2014 3:15am

Hi,

Check the below linke for 112 use.

http://www.katieandemil.com/t-sql-yyyymmdd

April 11th, 2014 3:19am

but what is the meaning of 112 ?. Can you please explain it in more details. Thanks in advance
'112' means it will show the date in NVarchar format, that is YYYYMMDD.
Free Windows Admin Tool Kit Click here and download it now
April 11th, 2014 3:19am

This topic is archived. No further replies will be accepted.

Other recent topics Other recent topics