DotDragnet
May 24, 2012, 07:01:42 AM *
Welcome, Guest. Please login or register.

Login with username, password and session length
News: follow us on twitter @dotdragnet
 
   Home   Help Search Login Register  
Pages: [1]   Go Down
  Print  
Author Topic: SQLing stuff together  (Read 528 times)
Johnathan
Full Member
***
Posts: 145



johnthan1707 johnathan1707
View Profile WWW Awards
« on: September 06, 2011, 08:22:11 AM »

Hello. In my user table I have first_name and last_name, is there anyway I can get both of them, stick them together with a space inbetween and have it come out as display_name, like "first_name . ' ' . last_name as display_name" or something like that?
Logged

8==D~ hitler
SAMMo_0
Full Member
***
Posts: 232


I AM STANDING BEHIND YOU


SAMMo_0
View Profile Awards
« Reply #1 on: September 06, 2011, 08:24:03 AM »

insert a blank gif to take up the space.

LOL ONLY KIDDING I'M JUST A MOTHER FLIPPING DESIGNER!!! HAHAHAHAAAA!!!!

The answer could be cats for all I know.

<edited to take screw out>
« Last Edit: September 06, 2011, 08:27:14 AM by SAMMo_0 » Logged

All your threads are belong to us.
Dom
Hero Member
*****
Posts: 1681


Taster of pasities. Clanger of both pots AND pans.


DominicNeagle
View Profile Awards
« Reply #2 on: September 06, 2011, 08:25:16 AM »

For T-SQL:

Code:
SELECT first_name + ' ' + last_name AS 'full_name'
FROM tblUsers

I'm not sure if you need to put the "AS 'full_name'" bit in, but it helps if you're referencing that "column" when ordering etc.
« Last Edit: September 06, 2011, 08:31:22 AM by Dom » Logged

neal
Sr. Member
****
Posts: 300



nealio82
View Profile Awards
« Reply #3 on: September 06, 2011, 08:26:15 AM »

SELECT CONCAT(`first_name`, ' ', `last_name`) AS display_name FROM [table_name]...
Logged

sig edited due to migrating from .net
Johnathan
Full Member
***
Posts: 145



johnthan1707 johnathan1707
View Profile WWW Awards
« Reply #4 on: September 06, 2011, 08:26:44 AM »

Camelcase? Really? Also, Mr. France suggested CONCAT(), is one better than the other?
Logged

8==D~ hitler
Dom
Hero Member
*****
Posts: 1681


Taster of pasities. Clanger of both pots AND pans.


DominicNeagle
View Profile Awards
« Reply #5 on: September 06, 2011, 08:28:23 AM »

Are you using SQL Server (T-SQL) or MySQL?
Logged

Johnathan
Full Member
***
Posts: 145



johnthan1707 johnathan1707
View Profile WWW Awards
« Reply #6 on: September 06, 2011, 08:29:41 AM »

MySQL
Logged

8==D~ hitler
Dom
Hero Member
*****
Posts: 1681


Taster of pasities. Clanger of both pots AND pans.


DominicNeagle
View Profile Awards
« Reply #7 on: September 06, 2011, 08:31:08 AM »

Oh. Ignore my reply then.


More than usual, I mean.
Logged

Johnathan
Full Member
***
Posts: 145



johnthan1707 johnathan1707
View Profile WWW Awards
« Reply #8 on: September 06, 2011, 08:34:34 AM »

Cool. No probs.

Just need to wait on the server coming back online before I can try poo out.
Logged

8==D~ hitler
neal
Sr. Member
****
Posts: 300



nealio82
View Profile Awards
« Reply #9 on: September 06, 2011, 08:42:46 AM »

FFS, I gave you the answer above. Don't give Mr France all the f*****g credit.
Logged

sig edited due to migrating from .net
Johnathan
Full Member
***
Posts: 145



johnthan1707 johnathan1707
View Profile WWW Awards
« Reply #10 on: September 06, 2011, 08:44:04 AM »

Mr. France said it on Twitter first though, but I'll use your example because he nested his and it looks stupid.
Logged

8==D~ hitler
neal
Sr. Member
****
Posts: 300



nealio82
View Profile Awards
« Reply #11 on: September 06, 2011, 08:48:23 AM »

I think you'll find I was busy writing a proper example as he just wrote concat and copied a url. I win the kudos.
Logged

sig edited due to migrating from .net
Dom
Hero Member
*****
Posts: 1681


Taster of pasities. Clanger of both pots AND pans.


DominicNeagle
View Profile Awards
« Reply #12 on: September 06, 2011, 08:50:13 AM »

Also, in your Tweet, you mention @mr_france but there is actually a @mr_france on Twitter:

http://twitter.com/mr_france

He's gonna wonder what the hell is going on.
Logged

Johnathan
Full Member
***
Posts: 145



johnthan1707 johnathan1707
View Profile WWW Awards
« Reply #13 on: September 06, 2011, 08:55:07 AM »

He deserves it for being so French.
Logged

8==D~ hitler
Pages: [1]   Go Up
  Print  
 
Jump to:  

Powered by MySQL Powered by PHP Powered by SMF | SMF © 2006-2008, Simple Machines Valid XHTML 1.0! Valid CSS!