Click here to Skip to main content
15,894,539 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
hi guys have a question for you guys

i have a column i am querying.

but the column contains values with and without julian dates in it i want to select the distinct values from these columns without the julian dates

if this is possible can someone please asset me?

Example of values:

BTH2010124
BTH2010123
BTH2010135
WCCH2010W

and the return i want from this
BTH
WCCH2010W
Posted

You have to look for patterns in the data. Right now, it looks like all of the strings returned that have the date in them start with "BTH", and end with a string of seven numbers. You could parse them based on that.

string x = "BTH2010124";
string prefix = x.Substring(0,3);
string possibleDate = x.Substring(3, 7);
if (int.TryParse(possibleDate))
{
    // remove the date part from the original string
    x = x.Replace(possibleDate, "");
}

// when you get here, the date will have been removed from x.


If you can't make the assumptions I made, then you're going to have to give us more info about your data.
 
Share this answer
 
v3
Comments
Unforgiv3n 25-Jun-10 6:03am    
the problem with this is that some values has more than 2 characters before the date for example :

BTHGH2010154
Based on your comment to my reply:

If the date is always at the end, you could reverse the string retrive the non-date portion, and then reverse it back:

string x = "ABCDEFG2010124";
string prefix = x.Substring(0,x.Length - 7);
string possibleDate = x.Substring(prefix.Length-1, 7);
if (int.TryParse(possibleDate))
{
    // remove the date part from the original string
    x = prefix;

// when you get here, the date will have been removed from x.


This is basic developemnt stuff. Since only you can identify the patterns, only YOU can come up with an acceptable parsing routine(s). There's no way you can provide all of the variations of the data you're retrieving, so there's really no way we can help beyond analyzing what we know based on what you provide.

Now, it's YOUR turn to be a programmer and come up with the code you need. It's really not that frakking hard.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900