Solved

How to take part of a text column and create a new column based on it

Posted on 2007-12-06
19
168 Views
Last Modified: 2010-03-20
I have a column named filenameimport.
So i want to take a piece of that name and put it into a new column
What can I do

Thanks
0
Comment
Question by:mphillip85
  • 7
  • 7
  • 4
  • +1
19 Comments
 
LVL 92

Expert Comment

by:Patrick Matthews
Comment Utility
More details, please.  Such as what is stored now, and how you want it split up.  Use examples,
please.
0
 

Author Comment

by:mphillip85
Comment Utility
Select FileNameImport FROM Table

expr1 = Mid(myFileNameImport,5)
0
 
LVL 92

Expert Comment

by:Patrick Matthews
Comment Utility
mphillip85,

Your response is not very helpful.  Are you saying you always want to break out the 5th through Nth
characters?

Regards,

Patrick
0
 

Author Comment

by:mphillip85
Comment Utility
I have a column in a view called FileNameImport
I want to put another column that has just a specific part of the filenameimport.

Suchas  Record1, so I want to make another expr1 = cord1

is this more helpful
0
 
LVL 92

Expert Comment

by:Patrick Matthews
Comment Utility
mphillip85 said:
>>is this more helpful

Frankly, no, it is not.

I need you to state a rule for dividing the string.  Without that rule, I cannot help you.

The rule could be something like:

"Everything from the 5th character and over"
"Everything following the first space"
"Everything following the last space"
"Everything between 'x' and 'y'"

or something more complex.  But there has to be a rule.
0
 
LVL 16

Expert Comment

by:Rick_Rickards
Comment Utility
hate to burst anyones bubble but matthewspatrick is right.  Without more information all we can really do is GUESS as to what you want.

What would be helpful is to say Something like this...

I have...

C:\folder1\folder2\file.txt

I want...

file.txt

*************

I have

C:\My Documents\My Name\Sample.pdf

I want...

Sample.pdf

************

Basically we need to have some idea what you are starting with and what you want to end up with when the query is done.  As soon as you can offer insight on that I have no doubt you're going to get a good answer.

Rick
0
 

Author Comment

by:mphillip85
Comment Utility
"Everything following the first space"

I can give you an example of what I would do in VB .NET

myFilename = Mid(FileNameImport,InStr(FileNameImport,"_"))

So this looks for the character where it is located and gives it back to the MID which then gives me the
part of filenameimport (String) that I want.

0
 
LVL 26

Expert Comment

by:Zberteoc
Comment Utility
Replace _ with the character you want:
UPDATE tbl SET 

	othercolumn=SUBSTRING(FileNameImport ,charindex('_',FileNameImport),len(FileNameImport))

FROM 

	YourTable tbl

Open in new window

0
 
LVL 26

Expert Comment

by:Zberteoc
Comment Utility
You might need

charindex('_',FileNameImport)+1

if you want to get the name starting with the caharacter after the one you search.
0
IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

 
LVL 92

Expert Comment

by:Patrick Matthews
Comment Utility
mphillip85 said:
>>"Everything following the first space"

If what you want is the first space, then why are you using an underscore?
0
 

Author Comment

by:mphillip85
Comment Utility
now you showed me the character find for the index.
Now I need to get the last part of the filename, like
C:\test1
I need
test1
0
 

Author Comment

by:mphillip85
Comment Utility
Actually a specific character is what I meant
0
 
LVL 26

Expert Comment

by:Zberteoc
Comment Utility
Just replace the _ with "\".
0
 
LVL 26

Expert Comment

by:Zberteoc
Comment Utility
Replace the _ with whatever character you need. I speciffied that already.
0
 

Author Comment

by:mphillip85
Comment Utility
how do i get the rest of the name.  I am getting the index now
0
 
LVL 26

Expert Comment

by:Zberteoc
Comment Utility
What index are you talking about ???
0
 
LVL 26

Expert Comment

by:Zberteoc
Comment Utility
Give me an example of file name here and what you want to extract from it.
0
 

Author Comment

by:mphillip85
Comment Utility
12122007142501_Company_test1_11012007.rtf
and i want
Company_test1_11012007.rtf


thanks
0
 
LVL 26

Accepted Solution

by:
Zberteoc earned 500 total points
Comment Utility
Use this:


UPDATE tbl SET 

	othercolumn=SUBSTRING(FileNameImport ,charindex('_',FileNameImport)+1,len(FileNameImport))

FROM 

	YourTable tbl

Open in new window

0

Featured Post

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Confronted with some SQL you don't know can be a daunting task. It can be even more daunting if that SQL carries some of the old secret codes used in the Ye Olde query syntax, such as: (+)     as used in Oracle;     *=     =*    as used in Sybase …
Composite queries are used to retrieve the results from joining multiple queries after applying any filters. UNION, INTERSECT, MINUS, and UNION ALL are some of the operators used to get certain desired results.​
It is a freely distributed piece of software for such tasks as photo retouching, image composition and image authoring. It works on many operating systems, in many languages.
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…

772 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now