1

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

2 Answers 2

2

1) You got value "NA" in column "Max weight". So Sql server can not convert it to int.

2) Should be where ["Sex"] = 'male'

Sign up to request clarification or add additional context in comments.

Comments

0
  select ["Max Weight"]
from dbo.animaldata
where ["Max Weight"]>5 AND  ["Max Weight"]!='N/A'

1 Comment

Doesn't help. You can use CASE statement however.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.