February 23, 2017 at 10:58 am
SELECT MAX(CASE code WHEN 'sdt' THEN convert(datetime,Cval) ELSE NULL END) as MinDate,
MAX(CASE code WHEN 'Edt' THEN convert(datetime,Cval) ELSE NULL END) as MaxDate
from table
Cval in table is varchar(20). value holds in this column is '2015034' Now I have to compare this coulm value to datetime valve for that in the query how Cval column will be converted to datetime?
February 23, 2017 at 11:10 am
mcfarlandparkway - Thursday, February 23, 2017 10:58 AMSELECT MAX(CASE code WHEN 'sdt' THEN convert(datetime,Cval) ELSE NULL END) as MinDate,
MAX(CASE code WHEN 'Edt' THEN convert(datetime,Cval) ELSE NULL END) as MaxDate
from table
Cval in table is varchar(20). value holds in this column is '2015034' Now I have to compare this coulm value to datetime valve for that in the query how Cval column will be converted to datetime?
If I had to convert 2015034 to a date, I wouldn't have a clue how to do it. Can you explain?
If you haven't even tried to resolve your issue, please don't expect the hard-working volunteers here to waste their time providing links to answers which you could easily have found yourself.
February 23, 2017 at 11:22 am
My best guess is that the value is a pseudo-"Julian" date (as IBM called it), i.e., that the last 3 digits are the relative day number of the year.
IF that's true, you can do this:
SELECT DATEADD(DAY, CAST(RIGHT(Cval, 3) AS int) - 1, LEFT(Cval, 4) + '0101') AS final_date
FROM (
VALUES('2015034')
) AS test_data(Cval)
SQL DBA,SQL Server MVP(07, 08, 09) A socialist is someone who will give you the shirt off *someone else's* back.
February 23, 2017 at 11:23 am
Phil Parkin - Thursday, February 23, 2017 11:10 AMmcfarlandparkway - Thursday, February 23, 2017 10:58 AMSELECT MAX(CASE code WHEN 'sdt' THEN convert(datetime,Cval) ELSE NULL END) as MinDate,
MAX(CASE code WHEN 'Edt' THEN convert(datetime,Cval) ELSE NULL END) as MaxDate
from table
Cval in table is varchar(20). value holds in this column is '2015034' Now I have to compare this coulm value to datetime valve for that in the query how Cval column will be converted to datetime?
If I had to convert 2015034 to a date, I wouldn't have a clue how to do it. Can you explain?
Wonder if its a year and some form of Julian date, possibly where 034 is representing the day of the year.
--Jeff Moden
Change is inevitable... Change for the better is not.
Viewing 4 posts - 1 through 3 (of 3 total)
You must be logged in to reply to this topic. Login to reply