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 |
|
AdamWest
Constraint Violating Yak Guru
360 Posts |
Posted - 2011-11-10 : 14:34:44
|
| I have a funny case where a piece of data needed, is actually embedded in a column of data looking something like this:note that is a shop with strong legacy mess still in place.adlu201008270919_3.zip the date is what i need and is embedded.ihave code to do this here:AND CAST(SUBSTRING(M.MDS_FILE,5,4) + '-' + SUBSTRING(M.MDS_FILE,9,2) + '-' + SUBSTRING(M.MDS_FILE,11,2) as datetime)but now i find out that where you have here 'adlu' that is 4 pos. it can be 3 or 2 or 1.so i have to code for that i have come up with this: but its not compiling:AND CASE WHEN WHEN CAST(SUBSTRING(M.MDS_FILE,5,4) + '-' + SUBSTRING(M.MDS_FILE,9,2) + '-' + SUBSTRING(M.MDS_FILE,11,2) as datetime) ELSE WHEN OEN.LENGTH(S.FACILITY_KEY) = 3 THEN CAST(SUBSTRING(M.MDS_FILE,4,4) + '-' + SUBSTRING(M.MDS_FILE,8,2) + '-' + SUBSTRING(M.MDS_FILE,10,2) as datetime)ELSE WHEN OEN.LENGTH(S.FACILITY_KEY) = 2 THEN CAST(SUBSTRING(M.MDS_FILE,3,4) + '-' + SUBSTRING(M.MDS_FILE,7,2) + '-' + SUBSTRING(M.MDS_FILE,9,2) as datetime)ELSE CAST(SUBSTRING(M.MDS_FILE,2,4) + '-' + SUBSTRING(M.MDS_FILE,6,2) + '-' + SUBSTRING(M.MDS_FILE,8,2) as datetime) END |
|
|
russell
Pyro-ma-ni-yak
5072 Posts |
Posted - 2011-11-10 : 14:39:09
|
In that case, the code I posted in your other thread on this will work.Also, how 'bout formatting your code. You've been around here long enough now for that. |
 |
|
|
AdamWest
Constraint Violating Yak Guru
360 Posts |
Posted - 2011-11-10 : 15:40:35
|
thank you i will format going forward..quote: Originally posted by russell In that case, the code I posted in your other thread on this will work.Also, how 'bout formatting your code. You've been around here long enough now for that. 
|
 |
|
|
X002548
Not Just a Number
15586 Posts |
|
|
russell
Pyro-ma-ni-yak
5072 Posts |
Posted - 2011-11-10 : 16:28:47
|
| Pretty sure he means the length of the prefix. |
 |
|
|
X002548
Not Just a Number
15586 Posts |
Posted - 2011-11-10 : 17:52:01
|
| OK, but what does THAT mean??It can be "adlu"Or it can be "salfdhyuweopi;rhg;lkehgou;ewngtwe"????And what about the _3??What can that be??is at least the .zip constant??2010 08 27 09 19So I'm guessing the date is ccyymmddhhmm??Little details actually kind of help usAnd more sample data would be good here, in DML formAnd the DDL of the tableso how do we find a pattern in a string VI know lots of languages that do that wellSo please state what you actually want to get out as well. That wouls also be a big helpBrett8-)Hint: Want your questions answered fast? Follow the direction in this linkhttp://weblogs.sqlteam.com/brettk/archive/2005/05/25/5276.aspxWant to help yourself?http://msdn.microsoft.com/en-us/library/ms130214.aspxhttp://weblogs.sqlteam.com/brettk/http://brettkaiser.blogspot.com/ |
 |
|
|
|
|
|
|
|