Solved

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

Posted on 2007-12-06
19
169 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
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
 

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 26

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 26

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
DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

 
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 26

Expert Comment

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

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 26

Expert Comment

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

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 26

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

If you find yourself in this situation “I have used SELECT DISTINCT but I’m getting duplicates” then I'm sorry to say you are using the wrong SQL technique as it only does one thing which is: produces whole rows that are unique. If the results you a…
If you have heard of RFC822 date formats, they can be quite a challenge in SQL Server. RFC822 is an Internet standard format for email message headers, including all dates within those headers. The RFC822 protocols are available in detail at:   ht…
This Micro Tutorial demonstrates using Microsoft Excel pivot tables, how to reverse engineer competitors' marketing strategies through backlinks.
Migrating to Microsoft Office 365 is becoming increasingly popular for organizations both large and small. If you have made the leap to Microsoft’s cloud platform, you know that you will need to create a corporate email signature for your Office 365…

910 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

22 Experts available now in Live!

Get 1:1 Help Now