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.
Author |
Topic |
sqlfresher2k7
Aged Yak Warrior
623 Posts |
Posted - 2009-08-26 : 11:03:27
|
[code]Below is my query when executed i got the errorSaying :Syntax error converting the varchar value '85sd' to a column of data type int.Select 'STUDENT GROUP: 15-50' as STUDENTAGE, Sum(Case When CONVERT(int,JYear) - CONVERT(int, BYear) Between 15 And 50 Then 1 Else 0 End) as count FROM dbo.studenttableWHERE BYear not like '%[^0-9]%' AND Jyear not like '%[^0-9]%'Sample date in the table:BYear Jyear---- ----1957 85sd1956 20081965 85sd1961 85sd1971 20081970 85sd1958 85sd1976 20081976 20081976 200819l7 2008I want to exclude the year from BYear, Jyear which are invalid value..Please help..[/code] |
|
Nageswar9
Aged Yak Warrior
600 Posts |
Posted - 2009-08-27 : 00:16:20
|
In the table, u hav varchar value (85sd), that's why query returns error. check it once |
|
|
webfred
Master Smack Fu Yak Hacker
8781 Posts |
Posted - 2009-08-27 : 07:36:37
|
quote: Originally posted by sqlfresher2k7
Below is my query when executed i got the errorSaying :Syntax error converting the varchar value '85sd' to a column of data type int.Select 'STUDENT GROUP: 15-50' as STUDENTAGE, Sum(Case When CONVERT(int,JYear) - CONVERT(int, BYear) Between 15 And 50 Then 1 Else 0 End) as count FROM dbo.studenttableWHERE BYear not like '%[^0-9]%' AND Jyear not like '%[^0-9]%'Sample date in the table:BYear Jyear---- ----1957 85sd1956 20081965 85sd1961 85sd1971 20081970 85sd1958 85sd1976 20081976 20081976 200819l7 2008I want to exclude the year from BYear, Jyear which are invalid value..Please help..
The query should work!Maybe the original query looks different? No, you're never too old to Yak'n'Roll if you're too young to die. |
|
|
sqlfresher2k7
Aged Yak Warrior
623 Posts |
Posted - 2009-08-27 : 10:48:17
|
I modified the query with below changes..Select 'STUDENT GROUP: 15-50' as STUDENTAGE, Sum(Case When CONVERT(int,JYear) - CONVERT(int, BYear) Between 15 And 50 Then 1 Else 0 End) as count FROM dbo.studenttableWHERE isdate(BYear) =1 AND ISDate(Jyear) =1It works.. |
|
|
|
|
|
|
|