--- I went with a version of Andrey Gurinov's answer because I wanted to do in the query and he posted it first. ----
I have a database with names, addresses, city, state, zip, ect. for people. I want to read the data into a C# program in order of a group code, name, then a date. I am running into a problem though because a name has been entered in multiple ways by people.
Here is an example of the problem with a subset of the data:
| Dr. Kristen S | 2011-04-15 00:00:00.000 | 00005573
| Kristen S | 2012-04-11 00:00:00.000 | 00005573
| Kristen S | 2012-08-10 00:00:00.000 | 00005573
| Ms Kristen S | 2011-08-12 00:00:00.000 | 00005573
| MS Kristen S | 2012-01-27 00:00:00.000 | 00005573
| Ms. KRISTEN S | 2012-04-09 00:00:00.000 | 00005573
As you can see, the name is relativly the same but the order of dates is not what I want. I want the dates in order.
If I read this data into my C# program is there a way to make the select statement recognize the variations (Dr. , MS , Ms. , Ms , " " <- double space) and replace them with nothing or a single space? So that I can then sort the name groups by date. Or would I have I have to remove the variations permenately in the database.
----- EDIT (SQL Query) -----
SELECT [ListMP]
,[Name]
,[Address1]
,[City]
,[State]
,[ZipCode]
,[Date]
,[OrderCode]
,[SequenceNbr]
FROM [Customer].[dbo].[Orders]
ORder by [OrderCode],[Name], [Date]
Sample output:
ORDER |Kristen S| 203 My Street| Bristol| RI| 02809| 2012-04-11 00:00:00.000| 05632| 00005573
The OrderCode is not unique to an individual, it's unique to an address where the address can have multiple people at.
00005573If it's person id or something, then it will be easy.ORDER BYclause?