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 |
memarcie
Yak Posting Veteran
91 Posts |
Posted - 2008-10-10 : 12:13:40
|
I have a column that holds a doctors degree(MD, DO, MSW) and I need to compare it against a master list which may not have the degree in the same order(DO, MD, MSW). I've been looking at several split functions, but I can't seem to figure out how to apply this to a column in both tables and then use the end result. They doctor may also have a partial degree(MD, DO). I need to return results of any in error(DO, MB).Here is some sample data.Table1doc specialty degree1 General MD, DO2 Therapy PT, MS3 General MB, DOTable2Specialty degreeGeneral DO, MDTherapy PT, MS, MSWThanks |
|
hanbingl
Aged Yak Warrior
652 Posts |
Posted - 2008-10-10 : 17:58:29
|
Hi, I have made a function to sort a comma delimited string. now you can compare one table to anotherEnjoy[code]CREATE function SortString(@string varchar(8000) )returns varchar(8000)asBEGINset @string = replace(@string,' ','')declare @pos intdeclare @piece varchar(500)if right(rtrim(@string),1) <> ',' set @string = @string + ','set @pos = patindex('%,%' , @string)declare @sort_table table (id int identity(1,1) not null, sortstr varchar(500))while @pos <> 0begin set @piece = left(@string, @pos - 1)insert into @sort_table (sortstr) values(cast(@piece as varchar(500))) set @string = stuff(@string, 1, @pos, '') set @pos = patindex('%,%' , @string)enddeclare @catstr varchar(8000), @thisstr varchar(500)set @catstr = ''declare curs cursor forselect sortstr from @sort_table order by sortstropen cursfetch next from curs into @thisstrwhile @@FETCH_STATUS=0beginset @catstr = @catstr + @thisstrfetch next from curs into @thisstrif @@FETCH_STATUS=0 begin set @catstr = @catstr + ','endendclose cursdeallocate cursreturn @catstrEND[/CODE] |
 |
|
memarcie
Yak Posting Veteran
91 Posts |
Posted - 2008-10-15 : 07:33:57
|
Thanks! |
 |
|
|
|
|
|
|