Tuesday, March 27, 2012

Con Cat In Ate

I have a first name and a last name, in two different fields. I use a simple bit of SQL to show them together.

SELECT
{fn concat(dbo.table_employee.first_name , dbo.table_employee.last_name)}
FROM
dbo.table_employee

Gives me results like BradWilliams and DarWilliams and such.

Simple enough. But, it would be nice to put a space between first name and last name. And that is sending me for a loop. Any advise?

Thanks,
DanDan
why do it at SQL level - do it at the presentation / UI level, unless you have a direct need - ie the export from the SQL goes to another process.

how do you handle null forenames. depending on the SQL engine you are using you could write a function to do this.|||SELECT
{fn concat (dbo.table_employee.first_name,
{fn concat (' ', dbo.table_employee.last_name)})}
FROM
dbo.table_employee|||Perfect, Ida, that got it, thank you|||I wouldn't go so far as 'perfect'
say Fname= "Dan", SName="Srobe"
SQL returns: "Dan_Srobe"
say Fname= SName="Dansrobe"
SQL returns: "_Dansrobe", when I'm guessing you would want "Dansrobe" with no space "_".
It becomes more of a problem if you want to build a name from say Title,FName,SName,Qualifications where you could end up with
"__Dansrobe_"

still if it works appropriately then maybe it is "perfect" after all.

No comments:

Post a Comment