Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2005 Forums
 Transact-SQL (2005)
 conversion can be difficult

Author  Topic 

Kurmanc
Yak Posting Veteran

92 Posts

Posted - 2008-04-25 : 10:39:49
--This is works
SELECT *
from vwClientsByAge
WHERE age like '18'

--This gives me an error
SELECT clientId, firstName, age
from vwClientsByAge
WHERE age < CONVERT(int, '18')

Error: The conversion of a char data type to a datetime data type resulted in an out-of-range datetime value.

Whats wrong with the conversion?

However, this works:
SELECT age
from vwClientsByAge
WHERE age < CONVERT(int, '18')

What is wrong?

SwePeso
Patron Saint of Lost Yaks

30421 Posts

Posted - 2008-04-25 : 10:52:36
Because you have values in Age column that can not be translated/converted as a number.
What datatype does AGE have?



E 12°55'05.25"
N 56°04'39.16"
Go to Top of Page

Kurmanc
Yak Posting Veteran

92 Posts

Posted - 2008-04-25 : 10:56:17
Age has varchar(3) as datatype. That is why I try to convert.
Go to Top of Page

SwePeso
Patron Saint of Lost Yaks

30421 Posts

Posted - 2008-04-25 : 11:01:16
First do a

SELECT * FROM vwClientsByAge WHERE AGE NOT LIKE '%[^0-9]%'

to get all records that have other characters than 0-9 within.



E 12°55'05.25"
N 56°04'39.16"
Go to Top of Page
   

- Advertisement -