473,795 Members | 2,452 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Parse fields

Hi there,

I am re-organizing the database. We used to have field 'names' in our
table for our first name and last name. However, I want to have those
names in different field.

FYI, I have two different tables in different databases. The A
database contains A table with 'names" field. The B database contains
B table with 'fname' and 'lname' I want to copy data A table to B
table.

How can I parse names field into first name and last name fields?

Here are some examples which are in the database.
(
id names
01 John Doe
02 John & Jane Doe
03 Mr & Mrs Doe
) something like this. It might contain '&' and two names. If there
are two names, then use first name.
Thanks guys,

Mar 9 '07 #1
5 4354
Do something like this
declare @tbla table ( id int ,names varchar(100))
insert into @tbla values (1,'John Doe')
insert into @tbla values (1,'John & Jane Doe')
insert into @tbla values (1,'Mr & Mrs Doe ')

select
id,
firstname = case when names like '%&%' then names
else
case when charindex(' ',names) 0
then substring(names ,1,charindex(' ',names) - 1)
else names
end
end ,
lastname = case when names like '%&%' then ''
else
case when charindex(' ',names) 0
then substring(names ,charindex(' ',names)+ 1,len(names) -
charindex(' ',names))
else names
end
end

from @tbla

M A Srinivas


On Mar 9, 1:20 pm, "portCo" <woos...@gmail. comwrote:
Hi there,

I am re-organizing the database. We used to have field 'names' in our
table for our first name and last name. However, I want to have those
names in different field.

FYI, I have two different tables in different databases. The A
database contains A table with 'names" field. The B database contains
B table with 'fname' and 'lname' I want to copy data A table to B
table.

How can I parse names field into first name and last name fields?

Here are some examples which are in the database.
(
id names
01 John Doe
02 John & Jane Doe
03 Mr & Mrs Doe
) something like this. It might contain '&' and two names. If there
are two names, then use first name.

Thanks guys,

Mar 9 '07 #2
On Mar 9, 10:46 am, masri...@gmail. com wrote:
Do something like this
declare @tbla table ( id int ,names varchar(100))
insert into @tbla values (1,'John Doe')
insert into @tbla values (1,'John & Jane Doe')
insert into @tbla values (1,'Mr & Mrs Doe ')

select
id,
firstname = case when names like '%&%' then names
else
case when charindex(' ',names) 0
then substring(names ,1,charindex(' ',names) - 1)
else names
end
end ,
lastname = case when names like '%&%' then ''
else
case when charindex(' ',names) 0
then substring(names ,charindex(' ',names)+ 1,len(names) -
charindex(' ',names))
else names
end
end

from @tbla

M A Srinivas

On Mar 9, 1:20 pm, "portCo" <woos...@gmail. comwrote:
Hi there,
I am re-organizing the database. We used to have field 'names' in our
table for our first name and last name. However, I want to have those
names in different field.
FYI, I have two different tables in different databases. The A
database contains A table with 'names" field. The B database contains
B table with 'fname' and 'lname' I want to copy data A table to B
table.
How can I parse names field into first name and last name fields?
Here are some examples which are in the database.
(
id names
01 John Doe
02 John & Jane Doe
03 Mr & Mrs Doe
) something like this. It might contain '&' and two names. If there
are two names, then use first name.
Thanks guys,- Hide quoted text -

- Show quoted text -
The following will also work:

SELECT id,
names,
RTRIM(SUBSTRING (names, 1, CHARINDEX(' ', names) - 1)) fname,
CASE
WHEN CHARINDEX('&', names) 0 THEN
LTRIM(SUBSTRING (names, CHARINDEX('&', names) + 1, LEN(names)))
ELSE
LTRIM(SUBSTRING (names, CHARINDEX(' ', names), LEN(names)))
END lname
FROM tblA

Mar 9 '07 #3
On Mar 9, 12:20 am, "portCo" <woos...@gmail. comwrote:
Hi there,

I am re-organizing the database. We used to have field 'names' in our
table for our first name and last name. However, I want to have those
names in different field.

FYI, I have two different tables in different databases. The A
database contains A table with 'names" field. The B database contains
B table with 'fname' and 'lname' I want to copy data A table to B
table.

How can I parse names field into first name and last name fields?

Here are some examples which are in the database.
(
id names
01 John Doe
02 John & Jane Doe
03 Mr & Mrs Doe
) something like this. It might contain '&' and two names. If there
are two names, then use first name.

Thanks guys,
Thanks guys

Mar 10 '07 #4
>How can I parse names field [sic] into first name and last name fields [sic]? <<

Don't do it. Name handling is an ugly problem and if you have to do
this on a regular basis get a package designed for this kind of work.
Some companies are Group 1 Software, SSA (used to have a great booklet
on this topic), Melissa Data Corporation and Promark Software Inc.

Their software handles mailing lists and you can get a review copy
from Melissa Data. They do not choke on names like "John Paul van der
Poon" and worse.

Mar 10 '07 #5
On Mar 9, 2:20 pm, "portCo" <woos...@gmail. comwrote:
Hi there,

I am re-organizing the database. We used to have field 'names' in our
table for our first name and last name. However, I want to have those
names in different field.

FYI, I have two different tables in different databases. The A
database contains A table with 'names" field. The B database contains
B table with 'fname' and 'lname' I want to copy data A table to B
table.

How can I parse names field into first name and last name fields?

Here are some examples which are in the database.
(
id names
01 John Doe
02 John & Jane Doe
03 Mr & Mrs Doe
) something like this. It might contain '&' and two names. If there
are two names, then use first name.

Thanks guys,
hi,

select id,
fname = substring(ltrim (rtrim(names)), 1,charindex('
',ltrim(rtrim(n ames))) - 1),
lname = reverse(substri ng(reverse(ltri m(rtrim(names)) ),
1,charindex(' ',reverse(ltrim (rtrim(names))) ) - 1))
from Atable

HTH

Mar 12 '07 #6

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

Similar topics

6
6106
by: nate | last post by:
Hello, Does anyone know where I can find an ASP server side script written in JavaScript to parse text fields from a form method='POST' using enctype='multipart/form-data'? I'd also like it to parse the filename. <form name='form1' method='POST' enctype='multipart/form-data' action='sub.asp'> <input type='text' name='title1' value='value1'> <input type='file' name='file1'>
24
3177
by: | last post by:
Hi, I need to read a big CSV file, where different fields should be converted to different types, such as int, double, datetime, SqlMoney, etc. I have an array, which describes the fields and their types. I would like to somehow store a reference to parsing operations in this array (such as Int32.Parse, Double.Parse, SqlMoney.Parse, etc), so I can invoke the appropriate one without writing a long switch.
11
3622
by: hoopsho | last post by:
Hi Everyone, I am trying to write a program that does a few things very fast and with efficient use of memory... a) I need to parse a space-delimited file that is really large, upwards fo a million lines. b) I need to store the contents into a unique hash. c) I need to then sort the data on a specific field. d) I need to pull out certain fields and report them to the user.
5
9118
by: Michael C# | last post by:
Hi all, I'm about to start writing a routine to parse "standard" U.S. Addresses (if there is such a thing...) Before I jump off into this, I was just wondering if maybe someone out there had already seen some similar logic already implemented somewhere? Here's basically what I'm trying to do: 123 Sesame Street NW In this example, I want to parse out the Street Address as follows:
7
14174
by: Perks | last post by:
Hi. I am trying to find out if it is possible to open a pdf file from within PHP, and parse its contents in order to extract all form fieldnames that might have been previously setup within the pdf itself. I want to find this out so that I can then generate a HTML form with all required questions, which when submitted, will generate a fdf / xfdf file, using the techniques from the following tutorial
6
4495
by: artemetis | last post by:
Howdy! I've got a table with some contact information. uid, emailaddy, username The user name data is inconsistent.... some names are as Bill Jones, some are B.Jones and some are the email address as well. I need to parse through the fields and where there is a space between the names, break them out into two separate fields. I'm stumped!
5
1943
by: Adam Pelling | last post by:
I'm getting this error Parse error: syntax error, unexpected T_CONSTANT_ENCAPSED_STRING, expecting ')' in /home/neblncbt/public_html/forum/includes/acp/acp_board.php on line 69 Here is the acp_board.php file <?php /** * * @package acp
1
2087
by: jonnyrebsc | last post by:
All, I am new to VBA and programming in Access. I am trying to set up database to keep track of statistics. The problem that I am running into is that one of the fields is variable length (it has no upper limit to the entries though the each entries is separated by a comma and a is 8 characters long ) and I need to count the item in that field to as part of one of the statistics. Additionally this database is updated daily I need to ...
21
3847
by: dk4300 | last post by:
Context- I have a text file (.txt) that is comma delimited and has each text field surrounded in “”. It does not contain column headers. I need to import 50 of the 300 rows so am using code instead of linking or importing (via 'get external data') since it exceeds the 255+ limit. I am building a database in Access 2007 off this file. I have a table that shows every field number and field name in the text file. I added a Y/N box where...
0
9672
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9519
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
1
10164
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10001
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9042
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
6780
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5437
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5563
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
3
2920
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.