Reputation: 29
i have imported all of the data from a csv named animal data. I can query with select * (where i get the following results)
https://i.sstatic.net/evzjv.jpg
but when i try to query the following
select ["Max Weight"]
from dbo.animaldata
where ["Max Weight"] > 5
Msg 245, Level 16, State 1, Line 1
Conversion failed when converting the varchar value 'NA' to data type int.
select ["Sex"]
from animaldata
where ["Sex"] = "male"
Msg 207, Level 16, State 1, Line 3
Invalid column name 'male'.
Can anyone please tell me what am i doing wrong in both counts?
Hello again. i tried the query that you have posted but i got the following error:
Msg 245, Level 16, State 1, Line 9
Conversion failed when converting the varchar value 'NA' to data type int.
instead i used the following and it did produce the same results (381 rows):
select ["Max Weight"]
from dbo.animaldata
where ["Max Weight"] > '5' AND ["Max Weight"]!='N/A'
select ["Max Weight"]
from dbo.animaldata
where ["Max Weight"] > '5'
The problem is solved and i will leave it for future reference. Regards Panos
Regards Panos
Upvotes: 1
Views: 85
Reputation: 1136
select ["Max Weight"]
from dbo.animaldata
where ["Max Weight"]>5 AND ["Max Weight"]!='N/A'
Upvotes: 0
Reputation: 46
1) You got value "NA" in column "Max weight". So Sql server can not convert it to int.
2) Should be where ["Sex"] = 'male'
Upvotes: 2