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 |
|
Lionheart
Starting Member
41 Posts |
Posted - 2010-08-09 : 21:57:32
|
I have 2 tables from which I need to pull data. e.g.tbl_t1 (Region;CodeID)Region is a varchar and CodeID is an int, with one number e.g.US;1UK;2FR;3Can;4tbl_t2 (Manager;CodeID)Manager is the manager for a group of regions (varchar) and CodeID in this case is the all the CodeID's that s/he manages (I am thinking would need to be varchar, but confirmation on this would help) e.g.Fred;1,4Wilma;2,3I need to be able to pull a list of who manages each country e.g.select t1.region, t2.managerfrom tbl_t1 inner jointbl_t2 t2 on t1.codeID in t2.codeID Any suggestions on how I can get this to work? Is using "in" in the join or something equivalent possible? |
|
|
khtan
In (Som, Ni, Yak)
17689 Posts |
|
|
Lionheart
Starting Member
41 Posts |
Posted - 2010-08-09 : 22:42:45
|
| Sorry, I may have not been clear enough. The comma separated values are already in the tbl_t2. What I need is to join the rows if the codeID in tbl_t1 is part of the string of CSV CodeID's in tbl_t2.ThxLH |
 |
|
|
khtan
In (Som, Ni, Yak)
17689 Posts |
Posted - 2010-08-09 : 22:53:12
|
are you using SQL 2005/2008 ? you can use CROSS APPLY to a split function likeCSVTablefnParseList KH[spoiler]Time is always against us[/spoiler] |
 |
|
|
Lamprey
Master Smack Fu Yak Hacker
4614 Posts |
|
|
|
|
|