473,386 Members | 1,832 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

Split a field

Whats the best way to do the following?

Field1 in Table1 contains numbers and characters seperated by #
Examples: aaa#01, kjhkjhjh#21 and jlkjlkj#123

How can I create two new fields in Table1, one containing what is to
the left of the # and the other what is to the right?

Regards,
Ciarán

Jul 23 '05 #1
4 4082
On 12 May 2005 08:49:49 -0700, ch********@hotmail.com wrote:
Whats the best way to do the following?

Field1 in Table1 contains numbers and characters seperated by #
Examples: aaa#01, kjhkjhjh#21 and jlkjlkj#123

How can I create two new fields in Table1, one containing what is to
the left of the # and the other what is to the right?

Regards,
Ciarán


Hi Ciarán,

UPDATE MyTable
SET NewCol1 = LEFT(ConcatCol,
CHARINDEX('#', ConcatCol) - 1)
, NewCol2 = SUBSTRING(ConcatCol,
CHARINDEX('#', ConcatCol) + 1,
LEN(ConcatCol))
WHERE ConcatCol LIKE '%#%'

Best, Hugo
--

(Remove _NO_ and _SPAM_ to get my e-mail address)
Jul 23 '05 #2
Perfect.
Cheers!
Ciarán

Jul 23 '05 #3
Hugo,

How shoud I modify the SQL so that if there is no '#' in ConcatCol,
then NewCol1 = ConcatCol

Regards,
Ciarán

Jul 23 '05 #4
On 13 May 2005 03:07:06 -0700, ch********@hotmail.com wrote:
Hugo,

How shoud I modify the SQL so that if there is no '#' in ConcatCol,
then NewCol1 = ConcatCol

Regards,
Ciarán


Hi Ciarán,

UPDATE MyTable
SET NewCol1 = CASE
WHEN ConcatCol LIKE '%#%'
THEN LEFT(ConcatCol,
CHARINDEX('#', ConcatCol) - 1)
ELSE ConcatCol
END
, NewCol2 = CASE
WHEN ConcatCol LIKE '%#%'
THEN SUBSTRING(ConcatCol,
CHARINDEX('#', ConcatCol) + 1,
LEN(ConcatCol))
ELSE NULL
END

Or you could simply run two consecutive UPDATE statements (the one from
my first message, followed by an update that sets newcol1 equal to
concatcol for the remaining rows).

Best, Hugo
--

(Remove _NO_ and _SPAM_ to get my e-mail address)
Jul 23 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
by: Arjen | last post by:
Hi All, What I want to is using a string as PATTERN in a split function. This makes it possible for me to change the PATTERN on one place in my script... For example: $separator = ";"; $line...
19
by: David Logan | last post by:
We need an additional function in the String class. We need the ability to suppress empty fields, so that we can more effectively parse. Right now, multiple whitespace characters create multiple...
4
by: Paola | last post by:
How can I split a field that is being displayed as an asp:label with a dataview? Currently the field is being displayed using this code <asp:label id=dept runat="server" Font-Size="Smaller"...
11
by: pmarisole | last post by:
I am using the following code to split/join values in a multi-select field. It is combining all the values in All the records into one long string in each record in recordset. Example: I have a...
9
by: MrHelpMe | last post by:
Hello again experts, I have successfully pulled data from an LDAP server and now what I want to do is drop the data into a database table. The following is my code that will insert the data but...
1
by: Roy | last post by:
I have a table with two fields. I wish to separate all the data in one field and keep it listed against the information in the other field. The information within the field TicketStatus, I wish to...
1
by: dayharbor | last post by:
'Splits full name into first/last name fields Private Sub SplitNames() Dim rsNames As DAO.Recordset Dim SplitName As String 'split name field strSQL = "SELECT fldName FROM...
4
by: kaplan.gillian | last post by:
Hi everyone, I currently have an Access database that includes quite a few long memo fields. When I create a report of my data, Access does not allow the memo fields to be split with the page...
2
by: AdrianJ1980 | last post by:
Hi, I apologise for not providing a code basis for my question, but i really am stuck. Does anyone know how i can split a memo field, such as below, into separate records. (The data comes from...
5
sicarie
by: sicarie | last post by:
I am attempting to parse a CSV, but am not allowed to install the CSV parsing module because of "security reasons" (what a joke), so I'm attempting to use 'split' to break up a comma-delimited file....
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.