473,387 Members | 1,481 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,387 software developers and data experts.

Pulling first name out of a name column in DB

I built a webpage using vb.net (.net 2.0) that creates a form letter. This
letter pulls data from a database. Although I populate the address with the
person's full name, which comes from the name column of a customer table, I
need to just get the first name for the Dear part of the letter (ie: Dear
John instead of Dear John Smith). It would be easy if the name was in two
parts in the table (First name and Last name column) but, that isn't the
case.

I've been using a datalist to pull data out of the database and populate it
to the webpage. How could I just get the first name instead of the whole
name?

TIA,
Jim
Jan 4 '08 #1
5 1769

"Jim in Arizona" <ti*******@hotmail.comwrote in message
news:Oc**************@TK2MSFTNGP03.phx.gbl...
>I built a webpage using vb.net (.net 2.0) that creates a form letter. This
letter pulls data from a database. Although I populate the address with the
person's full name, which comes from the name column of a customer table, I
need to just get the first name for the Dear part of the letter (ie: Dear
John instead of Dear John Smith). It would be easy if the name was in two
parts in the table (First name and Last name column) but, that isn't the
case.

I've been using a datalist to pull data out of the database and populate
it to the webpage. How could I just get the first name instead of the
whole name?

TIA,
Jim
Jim,
Your first decision is where to do the extraction of the name. It will
be done either on the database server or by the application. If you are
using SQL Server you can create a computed colum which can be used to return
the name. If you are going to do it in the application then you will
extract the name from the returned database row.

Big problem is this: From this list of names what is the first name:

Jean Francois De Poulet
John Smith
Jean De Poulet

As you can see there is an exception for each rule. In over 30 years of
working databases I see this problem all the time. The simplest although
somewhat error prone is to split the name using space as the delimiter.
Then use the first member of the split. At least in the above list 2 of the
3 would be correct.

Living in Canada as you see makes this almost impossible.

You would do this either as a function if you are using the <%#
Eval("Name") %type binding you can create a function to return the value
and using this in the Eval expression or you can do the processing in the
ItemDataBound event of the datalist.

Hope this helps
Lloyd Sheen

Jan 4 '08 #2
You would do this either as a function if you are using the <%#
Eval("Name") %type binding you can create a function to return the value
and using this in the Eval expression or you can do the processing in the
ItemDataBound event of the datalist.

Hope this helps
Lloyd Sheen
Hi Lloyd.

I am using an SQL2K server. I am using Eval("Name") within the aspx page for
other data (address and amounts due). I also figured that I would somehow
have to use the space as the seperator between first and last name. I'm in
Arizona and so far I haven't seen any case in the database where there would
be a French style name (luckily) so I'm not too concerned about it.

I just don't know how I would make the function and incorporate that into
the Eval method. What about this other option you mentioned by using the SQL
instead ("using SQL Server you can create a computed colum ") Can you give
me an example of that? Perhaps that would be the easier way to go?

Thanks!!
Jan 4 '08 #3
On Jan 4, 1:41*pm, "Jim in Arizona" <tiltow...@hotmail.comwrote:
* *You would do this either as a function if you are using the <%#
Eval("Name") %type binding you can create a function to return the value
and using this in the Eval expression or you can do the processing in the
ItemDataBound event of the datalist.
Hope this helps
Lloyd Sheen

Hi Lloyd.

I am using an SQL2K server. I am using Eval("Name") within the aspx page for
other data (address and amounts due). I also figured that I would somehow
have to use the space as the seperator between first and last name. I'm in
Arizona and so far I haven't seen any case in the database where there would
be a French style name (luckily) so I'm not too concerned about it.

I just don't know how I would make the function and incorporate that into
the Eval method. What about this other option you mentioned by using the SQL
instead ("using SQL Server you can create a computed colum ") Can you give
me an example of that? Perhaps that would be the easier way to go?
To use User Defined Functions you must be at version SQL 2000 or
greater.

Transact-SQL to create the function would be something like:

create function [dbo].GetFirstName (@name
varchar(sizeofyourfullnamefield))
returns varchar(maxsizeforthefirstname)
as
declare @i int
set @i = charindex(' ', @name)
if (@i = 0)
return @name
else
return(left(@name, @i - 1)

Then in the EVAL (I assume the name of the name column is Name), just
use EVAL(dbo.getfirstname(Name)).

Note: This code is untested.
Jan 4 '08 #4
Jim,

For this problem I would not think one minute and just use the Split in VB
for Net. It is then the first row in the resulting table.

However about the problem Loyd is showing us. What do you think of our Dutch
names, which are used in Canada and the USA as well. Active in the dotNet
general newsgroup is Peter van der Goes an american MVP, who uses his
correct in Dutch written original name. (Some years ago somebody was faking
him. And used "Peter Van Der Goes", it was for all Dutch after a short
moment clear that it was a fake. We will never write original Dutch names
like that).

However, we have some use where we will write this as "Goes, Peter van der".
Because "van der" is wide common here. What is then the first name (the
comma can be as well a dot or whatever or just nothing) ?

Cor
"Jim in Arizona" <ti*******@hotmail.comschreef in bericht
news:Oc**************@TK2MSFTNGP03.phx.gbl...
>I built a webpage using vb.net (.net 2.0) that creates a form letter. This
letter pulls data from a database. Although I populate the address with the
person's full name, which comes from the name column of a customer table, I
need to just get the first name for the Dear part of the letter (ie: Dear
John instead of Dear John Smith). It would be easy if the name was in two
parts in the table (First name and Last name column) but, that isn't the
case.

I've been using a datalist to pull data out of the database and populate
it to the webpage. How could I just get the first name instead of the
whole name?

TIA,
Jim
Jan 5 '08 #5

"Jim in Arizona" <ti*******@hotmail.comwrote in message
news:Oc**************@TK2MSFTNGP03.phx.gbl...
>I built a webpage using vb.net (.net 2.0) that creates a form letter. This
letter pulls data from a database. Although I populate the address with the
person's full name, which comes from the name column of a customer table, I
need to just get the first name for the Dear part of the letter (ie: Dear
John instead of Dear John Smith). It would be easy if the name was in two
parts in the table (First name and Last name column) but, that isn't the
case.

I've been using a datalist to pull data out of the database and populate
it to the webpage. How could I just get the first name instead of the
whole name?

What's wrong with the Split statement in VB?

Jan 5 '08 #6

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

Similar topics

6
by: LRW | last post by:
I have an automated process which uploads a comma separated spreadsheet (csv) and inserts it into a database: $sql = "LOAD DATA INFILE '".$uploadfile."' INTO TABLE `tbl_tracking` FIELDS...
2
by: PuckInLA | last post by:
I have a question. I have some data that I am pulling into a dataset that needs to have each row of data emailed out. I got the email funciton working great but its extracting that data that is...
4
by: Skully Matjas | last post by:
I am using the following code (created by the wizard) to allow to bring my form to a particular entery. But when I edit the entery (ex: put new information into a blank cell), it puts that record...
1
by: Prasad Karunakaran | last post by:
I am using the C# DirectoryEntry class to retrieve the Properties of an user object in the Active Directory. I need to get the First Name and Last Name as properties. I know it is not supported...
2
by: Jourdan | last post by:
I have a form with several combo boxes in it. The combo boxes have columns titled: BulletID, BulletPoint, Rating When a user selects the BulletPoint they want, that BulletPoint is entered...
1
by: xx75vulcan | last post by:
I have created an ASP page that will "on the fly" create an XML feed from my MS SQL database and the contents within a specified table. The Feed: http://www.rockwood.k12.mo.us/news/rss.asp You...
3
by: dancole42 | last post by:
I have an InvoiceLines subform on an invoice table. In the subform, I have the following fields that are bound to the actual InvoiceLines table: Class (the type of product) Product (the...
0
by: Jerms | last post by:
Hello all, I've been using this site quite a bit since starting my project and have found it very helpful. I have run into a roadblock though that I cant seem to scrounge up a solution to. I...
7
by: Markalon | last post by:
Greetings. I'm new to Python programming, but I'm coming along. I'm having an issue trying to pull data from a CSV file created by an Excel spreadsheet (save as... csv function). What I need to do...
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
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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...
0
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,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
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.