1)select substring(substring(x,patindex('%[0-9]%', x),len(x)),1,charindex('.',substring(x,patindex('%[0-9]%', x),len(x)))-1) as FileDateInto #temp1from(select 'ABCD.20051201.dat' as x union allselect 'XYZ.dcntry.20060412.mdss' as x union allselect 'roger.dat' as x union allselect 'mnbc.200402.cimms' as x) twhere isdate(substring(substring(x,patindex('%[0-9]%', x),len(x)),1,charindex('.',substring(x,patindex('%[0-9]%', x),len(x)))-1)) = 12) select FileDate, (case len(FileDate) when 8 then datediff(d, convert(datetime, FileDate), getdate()) + 1 when 6 then datediff(d, convert(datetime, FileDate + '01'), getdate())+1 end) as Difffrom #temp1
Harsh AthalyeIndia."Nothing is Impossible"