briangriffin
Programmer
This query works fine:
Code:
select
b.VisitID,
cast(c.ResultRW as numeric(20,2)),
isnumeric(c.ResultRW)
from Livendb.dbo.LabRequisitions a inner join Livendb.dbo.LabSpecimens b
on a.VisitID = b.VisitID
and a.RequisitionID = b.RequisitionID
and a.SourceID = b.SourceID
inner join Livendb.dbo.LabSpecimenTests c
on a.VisitID = c.VisitID
and b.SpecimenID = c.SpecimenID
and b.SourceID = c.SourceID
and isnumeric(c.ResultRW) = 1
inner join Livendb.dbo.DLabTest e
on c.TestPrintNumberID = e.PrintNumberID
and e.Mnemonic in ('GLU','GLUBS','.HBGA1C')
Where
[b]--cast(c.ResultRW as numeric(20,2)) >= 180
[/b]and c.ResultDateTime is not null
order by 2
[/code}
However, when I uncomment the 'cast as numeric' line in the where clause, I get the 'error converting data type varchar to numeric' message. Why don't I get that same message from that conversion in the select clause? And how can I get around this efficiently? I get the same error when moving that line to the join.
TIA.