Solved

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

Posted on 2007-12-06
19
174 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 7
  • 7
  • 4
  • +1
19 Comments
 
LVL 92

Expert Comment

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

Author Comment

by:mphillip85
ID: 20422457
Select FileNameImport FROM Table

expr1 = Mid(myFileNameImport,5)
0
 
LVL 92

Expert Comment

by:Patrick Matthews
ID: 20422519
mphillip85,

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

Regards,

Patrick
0
How our DevOps Teams Maximize Uptime

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us. Read the use case whitepaper.

 

Author Comment

by:mphillip85
ID: 20422597
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
ID: 20422622
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
ID: 20422688
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
ID: 20422733
"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 27

Expert Comment

by:Zberteoc
ID: 20422986
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 27

Expert Comment

by:Zberteoc
ID: 20422999
You might need

charindex('_',FileNameImport)+1

if you want to get the name starting with the caharacter after the one you search.
0
 
LVL 92

Expert Comment

by:Patrick Matthews
ID: 20423083
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
ID: 20423090
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
ID: 20423113
Actually a specific character is what I meant
0
 
LVL 27

Expert Comment

by:Zberteoc
ID: 20423120
Just replace the _ with "\".
0
 
LVL 27

Expert Comment

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

Author Comment

by:mphillip85
ID: 20423135
how do i get the rest of the name.  I am getting the index now
0
 
LVL 27

Expert Comment

by:Zberteoc
ID: 20423139
What index are you talking about ???
0
 
LVL 27

Expert Comment

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

Author Comment

by:mphillip85
ID: 20423171
12122007142501_Company_test1_11012007.rtf
and i want
Company_test1_11012007.rtf


thanks
0
 
LVL 27

Accepted Solution

by:
Zberteoc earned 500 total points
ID: 20423309
Use this:


UPDATE tbl SET 
	othercolumn=SUBSTRING(FileNameImport ,charindex('_',FileNameImport)+1,len(FileNameImport))
FROM 
	YourTable tbl

Open in new window

0

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

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.​
This post looks at MongoDB and MySQL, and covers high-level MongoDB strengths, weaknesses, features, and uses from the perspective of an SQL user.
If you're a developer or IT admin, you’re probably tasked with managing multiple websites, servers, applications, and levels of security on a daily basis. While this can be extremely time consuming, it can also be frustrating when systems aren't wor…
Michael from AdRem Software explains how to view the most utilized and worst performing nodes in your network, by accessing the Top Charts view in NetCrunch network monitor (https://www.adremsoft.com/). Top Charts is a view in which you can set seve…

734 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