I have a table in SQL Server that contains 2 columns: Question_asked
, Response
The Response
column is of the datatype varchar(500)
and holds the users response to the question that is held in the column Question_asked
I have created a view V_age_attr
with the following SQL statement:
select
question_asked, cast(Response as integer)
from
main_table
where
question_asked = 'What is your age'
If I run a simple SQL query the results return as expected. But in some circumstances like when using a sum/group by query. I get an error msg (actual msg I get):
Conversion failed when converting the varchar value '2011-08-13 00:00:00' to data type int
In the table, main_table
, one of the questions is the start_date
, so the column Response
does hold date values in the table, but not in the view I created.
Again, I can run a select query and check all the values for my cast(Response as integer)
and they all are integer values.
My main question is: can anyone tell me if this is known/expected behavior in SQL Server 2008 R2, and/or does anyone else have another way to get a subset of values from this type of table other than creating a view?
Thank you