I have the following query that I have written for a database running on SQL 7.
The query relies on the users inserting a specific string into a memo field within the application which is stored in a CHAR field in the database. What they enter is
LRD dd/mm/yyyy
unfortunately this information can not be entered into any other date specific field, so I have to extract the date and convert to make it useable. (lrd also has to be entered)
The problem lies in that if the users input the date in the wrong format, such as
lrd 17/5/06
lrd 07-05-2006 etc...
the conversion will not take place.
What I would like to be able to do is to find away to pre-validate the date format before trying to convert the data within the script?
I know what I want, i'm just not sure how to get it?
Could anybody offer me an answer or at least a gently knudge in the right direction! ;-)
Thanks
Lewis
(Please see below for the script)
select m.serno, m.date as 'Memo_Date', convert(datetime,substring(m.line_mess,5, 10),103) as 'LRD_Date',
m.inits as 'Memo_inits',h.seq, h.state, P.DESC1,
h.date as 'History_date', h.inits as 'History_inits', h.letter_code, h.type, C.STATE AS 'PCN State', PP.DESC1 AS 'PCN DESC'
from cpmemo m
join cphist h on h.serno = m.serno
JOIN CPPROG P ON P.CODE = H.STATE AND P.TYPE = H.TYPE
JOIN CPCASE C ON C.SERNO = M.SERNO
JOIN CPPROG PP ON PP.CODE = C.STATE AND PP.TYPE = C.TYPE
where left(line_mess,3) = 'lrd' and convert(datetime,substring(m.line_mess,5, 10),103) between Startdate and Enddate
order by m.serno, h.seq
Lewis
United Kingdom
The query relies on the users inserting a specific string into a memo field within the application which is stored in a CHAR field in the database. What they enter is
LRD dd/mm/yyyy
unfortunately this information can not be entered into any other date specific field, so I have to extract the date and convert to make it useable. (lrd also has to be entered)
The problem lies in that if the users input the date in the wrong format, such as
lrd 17/5/06
lrd 07-05-2006 etc...
the conversion will not take place.
What I would like to be able to do is to find away to pre-validate the date format before trying to convert the data within the script?
I know what I want, i'm just not sure how to get it?
Could anybody offer me an answer or at least a gently knudge in the right direction! ;-)
Thanks
Lewis
(Please see below for the script)
select m.serno, m.date as 'Memo_Date', convert(datetime,substring(m.line_mess,5, 10),103) as 'LRD_Date',
m.inits as 'Memo_inits',h.seq, h.state, P.DESC1,
h.date as 'History_date', h.inits as 'History_inits', h.letter_code, h.type, C.STATE AS 'PCN State', PP.DESC1 AS 'PCN DESC'
from cpmemo m
join cphist h on h.serno = m.serno
JOIN CPPROG P ON P.CODE = H.STATE AND P.TYPE = H.TYPE
JOIN CPCASE C ON C.SERNO = M.SERNO
JOIN CPPROG PP ON PP.CODE = C.STATE AND PP.TYPE = C.TYPE
where left(line_mess,3) = 'lrd' and convert(datetime,substring(m.line_mess,5, 10),103) between Startdate and Enddate
order by m.serno, h.seq
Lewis
United Kingdom