Russell Jackson (rjackson@virtualpremise.com) writes:[color=blue]
> Sorry my description is unclear. Here is more info. The underlying
> table looks something like this,
>
> FormItemID FormItemAnswer(varchar)
> 3 5/6/1987
> 4 John Thompson
> 5 4/5/1902
> 6 234 Main St.
> 7 30115
> 3 6/7/1984
>
> The FormItemAnswer column is a varchar that stores the users 'answers'
> to the items on the web page, like name address, zip
>
> So the underlying view looks like,
>
> SELECT FormItemAnswer as [Lease End Date]
> FROM tblFormData
> WHERE FormItemID = 3
>
> Then the query that doesn't work calls that view and tries to do a range
> on the dates. The dates in the table are all valid, I've checked with a
> query just like the one you sent. The problem is that the query is
> trying to convert values for other FormItemIDs other than 3! It's like
> the execution order is whack. It's trying to do the where clause in the
> outer query before it does the where clause in the inner view.[/color]
Alright, I think it is time for the standard suggestion. Please post:
o CREATE TABLE statement for your table.
o INSERT statements with sample data giving you the problem.
o The output you are looking for from that sample.
o The query you have so far helps to.
I should point that the kind of processing you are into is a bit fragile.
It is possible that using sql_variant would help a little, but I am
not sure.
You might also consider adding a computed column to the table:
CREATE TABLE tbl (
itemid int NOT NULL,
answer varchar(30) NOT NULL,
dateanswer AS CASE WHEN isdate(answer) = 1
THEN convert(datetime, answer, 101)
ELSE NULL
END)
--
Erland Sommarskog, SQL Server MVP,
sommar@algonet.se
Books Online for SQL Server SP3 at
http://www.microsoft.com/sql/techinf...2000/books.asp