| Author |
Topic |
|
pazzy11
Posting Yak Master
145 Posts |
Posted - 2008-07-30 : 06:57:54
|
| Hi I am trying to join 2 tables, one has code as its primary key (int) i am comparing it to part of a field of another table that will have a code as part of the string.. so ex table A CODE (int)NAME (varchar)Table Bnames (varchar) example 'dan12jui' - the 4th and 5th chars are ALWAYS numbers..join is [CODE]A.CODE = substring(B.names,4,2)[/CODE]and i've tried [CODE]A.CODE = CAST(substring(B.names,4,2) as int) [/CODE]and[CODE]A.CODE = CONVERT(int,substring(B.names,4,2)) [/CODE]But i still get an error :Server: Msg 245, Level 16, State 1, Line 2Syntax error converting the varchar value 'y ' to a column of data type int. |
|
|
madhivanan
Premature Yak Congratulator
22864 Posts |
Posted - 2008-07-30 : 07:04:39
|
| You have some invalid data. Can you post some more sample data?MadhivananFailing to plan is Planning to fail |
 |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2008-07-30 : 07:22:16
|
| The error clearly suggests that part you extracted contains character y which it cant convert to int. so i dont think your assumption that 4th & 5th character will be a number is correct. |
 |
|
|
pazzy11
Posting Yak Master
145 Posts |
Posted - 2008-07-30 : 08:15:58
|
| Well i did a distinct select of substring(B.names,4,2) and it is always numeric .. |
 |
|
|
SwePeso
Patron Saint of Lost Yaks
30421 Posts |
Posted - 2008-07-30 : 08:24:15
|
Then where do you think the error message originates from? E 12°55'05.25"N 56°04'39.16" |
 |
|
|
madhivanan
Premature Yak Congratulator
22864 Posts |
Posted - 2008-07-30 : 08:24:56
|
quote: Originally posted by pazzy11 Well i did a distinct select of substring(B.names,4,2) and it is always numeric ..
Can you post the full code you used?MadhivananFailing to plan is Planning to fail |
 |
|
|
pazzy11
Posting Yak Master
145 Posts |
Posted - 2008-07-31 : 09:02:05
|
| FULL CODE of QRY not working [CODE]select s.name as category, si.site as site, --substring(eu.usr_name,4,2) as site, eu.usr_name as agent, avg(a.duration) as AHT_TOTALfrom action a, interaction i, easyBO..skill s,easyBO..e_user eu,sites siwhere-- joins --a.interaction_id = i.code andi.skill_id = s.code anda.agent_id = eu.code anda.agent_id != 698 and -- not itcorp-- filters --i.skill_id is not null anda.type_desc_id in (51,52) anda.duration is not null anda.agent_id != 698 and -- not itcorporate..i.code in( select code from interaction where status in(9,20) and dateadd(second, duration, start_moment) between '2008-06-01' and '2008-06-02')--and i.code not in--(select * from #T4) -- we want one shots...andsi.code = cast(substring(eu.usr_name,4,2) as int)group by s.name,si.site,eu.usr_name[/CODE]************************************************************************************************************************************************************************************************************************************************This qry below is the same except it's using site code taken from the agent name, (no join with site)and it works[CODE]select s.name as category, substring(eu.usr_name,4,2) as site, eu.usr_name as agent, avg(a.duration) as AHT_TOTALfrom action a, interaction i, easyBO..skill s,easyBO..e_user euwhere-- joins --a.interaction_id = i.code andi.skill_id = s.code anda.agent_id = eu.code anda.agent_id != 698 and -- not itcorp-- filters --i.skill_id is not null anda.type_desc_id in (51,52) anda.duration is not null anda.agent_id != 698 and -- not itcorporate..i.code in( select code from interaction where status in(9,20) and dateadd(second, duration, start_moment) between '2008-06-01' and '2008-06-02')--and i.code not in--(select * from #T4) -- we want one shots...GROUP BY s.name,substring(eu.usr_name,4,2),eu.usr_name[/CODE]I would like to post some sample data .. i cant attach a file .. |
 |
|
|
madhivanan
Premature Yak Congratulator
22864 Posts |
Posted - 2008-07-31 : 09:23:04
|
| See what you getSelect usr_name,substring(usr_name,4,2) from easyBO..e_user where substring(usr_name,4,2) like '%[^0-9]%'MadhivananFailing to plan is Planning to fail |
 |
|
|
pazzy11
Posting Yak Master
145 Posts |
Posted - 2008-07-31 : 09:44:46
|
| same error .. |
 |
|
|
madhivanan
Premature Yak Congratulator
22864 Posts |
Posted - 2008-07-31 : 09:51:36
|
quote: Originally posted by pazzy11 same error ..
Did you execute this?Select usr_name,substring(usr_name,4,2) from easyBO..e_user where substring(usr_name,4,2) like '%[^0-9]%'MadhivananFailing to plan is Planning to fail |
 |
|
|
pazzy11
Posting Yak Master
145 Posts |
Posted - 2008-07-31 : 10:04:41
|
| same error as it needs to be numeric in the 4th AND 5th .. so something like where (substring(usr_name,4,1) like '%[^0-9]%' ANDsubstring(usr_name,4,2) like '%[^0-9]%') |
 |
|
|
madhivanan
Premature Yak Congratulator
22864 Posts |
Posted - 2008-07-31 : 10:07:56
|
quote: Originally posted by pazzy11 same error as it needs to be numeric in the 4th AND 5th .. so something like where (substring(usr_name,4,1) like '%[^0-9]%' ANDsubstring(usr_name,4,2) like '%[^0-9]%')
I asked you to execute just this querySelect usr_name,substring(usr_name,4,2) from easyBO..e_user where substring(usr_name,4,2) like '%[^0-9]%'and see what you getMadhivananFailing to plan is Planning to fail |
 |
|
|
pazzy11
Posting Yak Master
145 Posts |
Posted - 2008-07-31 : 10:10:56
|
| ah yes !!this seems to give me the problematic cases ...does the ^ symbol mean "not like" =? |
 |
|
|
madhivanan
Premature Yak Congratulator
22864 Posts |
Posted - 2008-07-31 : 10:16:51
|
quote: Originally posted by pazzy11 ah yes !!this seems to give me the problematic cases ...does the ^ symbol mean "not like" =?
YesMadhivananFailing to plan is Planning to fail |
 |
|
|
|