I’ve got the following piece of code which exectues within no problem
SELECT (
CASE WHEN
(SELECT DateDiff (Day, (
SELECT ChildDOB1 FROM MatterDataDef Where ptMatter = $Matter$),
GETDATE()))>6574 THEN '(over 18)'
ELSE '(' + ChildDOB1 + ')'
END)
FROM dbo.MatterDataDef WHERE ptMatter = $Matter$
Howeveer, when i attempt to wrap the code in brackets (so i can use it as part of a longer equation) i get the following error ‘Conversion failed when converting datetime from character string’
any help appreciated 🙂
This is equivalent to your code. The extra subquery and brackets are all unnecessary.
The problem is that you are adding childdob1 (datetime) to the brackets without converting to varchar. But did you actually want the DOB in a particular format, or the age?