I don't think there will be a logically simpler code than you publish the source code, I am also looking for other ways to try to rewrite it on the Internet, the existing solution is to create a udf, but that implementation is also based on this code, and does not Universal.
Through the query, it is found that julian currently only exists in the database under IBM, DB2 has the JULIAN_DAY function, we have not heard of this special name in sql server, I will directly explain the part of this code to you below. On the premise that you know the functions of right and substring.
The first three lines of the code directly calculate the exact time 20:35:10.000 after the date,First, the first step is to concatenate 000000 and 203510 of nvchar type from the incoming variable val1 to get 000000203510, intercept 6 characters from right to left to get 203510, use the substring function to extract the characters of length 2, and get it before the first comma 20, substring (@val1, 3, 2) gets 35, substring (@val1, 5, 2) gets 10, use dec to control the precision of the output, and the date will be obtained through some operations later, you should try it yourself, This is interesting code.
As for people saying your code is incomplete, yes, it doesn't work because you define nothing and the basic syntax is wrong. Attach the correct DDL for follow up.
--DDL
declare @Val1 VARCHAR(6) = '203510'
declare @Val2 VARCHAR(6) ='122189'
SELECT dateadd(hour,cast(substring(right('000000'+cast(@Val1 as nvarchar),6),1,2) as dec(2,0)),
dateadd(minute,cast(substring(right('000000'+cast(@Val1 as nvarchar),6),3,2) as dec(2,0)),
dateadd(second,cast(substring(right('000000'+cast(@Val1 as nvarchar),6),5,2) as dec(2,0)),
cast(convert(varchar,
dateadd(dy,cast(substring(cast(@Val2+1900000 as nvarchar),5,3) as int)-1,
substring(cast(@Val2+1900000 as nvarchar),1,4)+'0101'),101) as datetime))))
Bert Zhou