I'm having a fit with a query for a range of dates. The dates are
being returned from a view. The table/field that they are being
selected from stores them as varchar and that same field also stores
other fields from our dynamic forms. The field is called
'FormItemAnswer ' and stores text, integer, date, float, etc. Anything
the user can type into one of our web forms. The query looks like,
select distinct [Lease End Date] from
vwFormItem_4_Ex pirationDateOfT erm where CONVERT(datetim e, [Lease End
Date], 101) >= CONVERT(datetim e, '08/03/2003', 101) AND
CONVERT(datetim e, [Lease End Date], 101) < CONVERT(datetim e,
'09/03/2003', 101)
The underlying view does a simple select based on the particular form
field, lease end date in this case.
This query works fine with 1 date in the where but with two fails with
the dreaded 'syntax error converting to datetime from varchar'.
What appears to be happening is sql is trying to do the CONVERTS
before it filters with the WHERE clause in the view.
I tried using a subquery but it still seems to do the same thing
somehow!
SELECT *
FROM (SELECT *
FROM vwFormItem_4_Mc D_Lease_4B_Expi rationDateOfTer m
WHERE isdate([Lease End Date]) = 1 ) derived
WHERE (CONVERT(dateti me, [Lease End Date], 101) >= CONVERT
(datetime, '#8/3/2003', 101)) AND (CONVERT(dateti me, [Lease End Date],
101)
<= CONVERT(datetim e, '9/3/2003', 101))
I've tried everything I know to try like doing the CONVERT inside the
view I'm selecting from, doing a datediff, everything. Really goin
crazy here.
Any ideas would be greatly appreciated!
Russell
being returned from a view. The table/field that they are being
selected from stores them as varchar and that same field also stores
other fields from our dynamic forms. The field is called
'FormItemAnswer ' and stores text, integer, date, float, etc. Anything
the user can type into one of our web forms. The query looks like,
select distinct [Lease End Date] from
vwFormItem_4_Ex pirationDateOfT erm where CONVERT(datetim e, [Lease End
Date], 101) >= CONVERT(datetim e, '08/03/2003', 101) AND
CONVERT(datetim e, [Lease End Date], 101) < CONVERT(datetim e,
'09/03/2003', 101)
The underlying view does a simple select based on the particular form
field, lease end date in this case.
This query works fine with 1 date in the where but with two fails with
the dreaded 'syntax error converting to datetime from varchar'.
What appears to be happening is sql is trying to do the CONVERTS
before it filters with the WHERE clause in the view.
I tried using a subquery but it still seems to do the same thing
somehow!
SELECT *
FROM (SELECT *
FROM vwFormItem_4_Mc D_Lease_4B_Expi rationDateOfTer m
WHERE isdate([Lease End Date]) = 1 ) derived
WHERE (CONVERT(dateti me, [Lease End Date], 101) >= CONVERT
(datetime, '#8/3/2003', 101)) AND (CONVERT(dateti me, [Lease End Date],
101)
<= CONVERT(datetim e, '9/3/2003', 101))
I've tried everything I know to try like doing the CONVERT inside the
view I'm selecting from, doing a datediff, everything. Really goin
crazy here.
Any ideas would be greatly appreciated!
Russell
Comment