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
Solved

How to insert firstname + lastname into fullname???

Posted on 2007-12-05
6
1,467 Views
Last Modified: 2012-06-21
Greetings all,

I have a table called Contacts. This table following:

FirstName,
LastName
Fullname. These are the core of my question.

During an INSERT statement, how do I insert the value of FirstName and Lastname into fieldname called Fullname. THis way, the values look like this:

FirstName    LastName          Full Name
John             Doe                  John Doe

So, insert statement would look like this:

INSERT INTO Contacts (FirstName, LastName, Fullname) Values (ValueOfFirstName, ValueOfLastName, ValueOfFirstName and LastName combined)

Thanks in advance
0
Comment
Question by:sammySeltzer
  • 3
  • 2
6 Comments
 
LVL 37

Expert Comment

by:samtran0331
ID: 20413933
There's really no need to have a column named "FullName", it can be a computed column.
When you need a full name, you can:

SELECT FirstName, LastName, FirstName+' '+LastName AS FullName FROM Contacts
0
 
LVL 28

Author Comment

by:sammySeltzer
ID: 20414104
Yes, in a sense you are right but here is where I am having issues.

Contact table is a lookup table to another table called Calls.

In other words, Calls table is dependent upon Contacts table for contact name.

So, if we have on Calls table the following:

ContactID,
Call_Date, etc

Now, any time we need to create a new call Record, we would search the Contact Dropdownlist to see if the Caller already exists there. If it does, we pull it and its id is stored on Calls table.

There are times when the wrong Contact name is pulled.

For instance, if We mistakenly pull Contact by the name Joe Blow with ContactID 123, and it turns out that Joe Blow is wrong. It is actually John Doe with contact Id 456, we will now need to update the Calls table.

My question then is how do we update Calls table giving that this is pullded from dropdownlist control and the dropdown is already a computed column?

Your assistance is appreciated and sorry for long, boring explanation.
0
 
LVL 23

Expert Comment

by:naveenkohli
ID: 20414192
INSERT INTO Contacts (FirstName, LastName, Fullname) Values (ValueFirstName, ValueOfLastName, ValueOfFirstName + " " + Value OfLastName)
0
Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
LVL 28

Author Comment

by:sammySeltzer
ID: 20414328
Ok,

I know that  but how do I code it in asp.net?

Here is the actual asp.net (vb) code:
                "INSERT INTO Contacts (FirstName, LastName, Fullname) " & _
                "VALUES (@FirstName,@LastName, @Fullname)", Conn)
            cmdcommand.Parameters.AddWithValue("@FirstName", FirstName.Text)
            cmdcommand.Parameters.AddWithValue("@LastName", LastName.Text)
            cmdcommand.Parameters.AddWithValue("@Fullname", System.Data.SqlDbType.NVarchar2)
            cmdcommand.Parameters("@Fullname").Value = ????

The problem with the above is that I don't want the to have to enter the FullName information.

As soon as the user enters value for firstname, lastname, I want those values inserted into the Fullname fieldname without human involvement.

Any ideas what the real syntax is?
0
 
LVL 37

Accepted Solution

by:
samtran0331 earned 50 total points
ID: 20414537
>>cmdcommand.Parameters("@Fullname").Value = ????

becomes:
cmdcommand.Parameters("@Fullname").Value = FirstName.Text & " " & LastName.Text
0
 
LVL 28

Author Comment

by:sammySeltzer
ID: 20414649
I almost figured that one out, not just smart enough.

Thank you!
0

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone 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

Suggested Solutions

Title # Comments Views Activity
ASCX file or a newer alternative? 1 40
Need help with building query string 2 21
How come this regular expression allows "e"? 14 44
FInd Image Control Gridview 3 19
Lots of people ask this question on how to extend the “MembershipProvider” to make use of custom authentication like using existing database or make use of some other way of authentication. Many blogs show you how to extend the membership provider c…
User art_snob (http://www.experts-exchange.com/M_6114203.html) encountered strange behavior of Android Web browser on his Mobile Web site. It took a while to find the true cause. It happens so, that the Android Web browser (at least up to OS ver. 2.…
Two types of users will appreciate AOMEI Backupper Pro: 1 - Those with PCIe drives (and haven't found cloning software that works on them). 2 - Those who want a fast clone of their boot drive (no re-boots needed) and it can clone your drive wh…

791 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