Is there a way in SQL Server
using T-SQL
to say:
WHERE CONVERT(date, mat1_04_05, 101) = true
I'm doing some reporting against an app that I don't have source for and the column is varchar
and I can't rely on user data.
EDIT
I tried using ISDATE
. However I'm still running into a conversion error this is the full query:
SELECT mat1_04_01 AS 'CaseStg',
matter.mat_no AS 'MatNo',
MAX(matter.client) AS 'Client',
MAX(mat1_03_01) AS 'InCo',
MAX(mat1_07_01) AS 'Clm Amt',
MAX(mat1_07_03) AS 'Clm Bal',
MAX(mat1_04_05) AS 'BilSnt',
MAX(mat1_01_07) AS 'Injured',
CONVERT(CHAR, MIN(CONVERT(DATE, usr1_02_01))) AS dos_start,
CONVERT(CHAR, MAX(CONVERT(DATE, usr1_02_02))) AS dos_end
FROM lntmuser.matter
INNER JOIN lntmuser.usertype1
ON lntmuser.matter.sysid = lntmuser.usertype1.mat_id
WHERE Isdate(mat1_04_05) = 1
AND Datediff(DAY, CONVERT(DATE, mat1_04_05, 101), Getdate()) > 31
AND mat1_04_01 LIKE 'BILLING MAILED OUT'
AND matter.status NOT LIKE 'CLOSED'
GROUP BY mat1_04_01,
matter.mat_no