user7151558
user7151558

Reputation:

Current query is not displaying user's full name

I need to display user's full name on the page. Should be formatted as follows:

Last Suffix, First Middle

Below is the query that displays the record on the page.

public String getSubjectSql()
{
    return
        " SELECT " +
        " u.c_last_name, u.c_suffix || ', ' || u.c_first_name, u.c_middle_name AS userName, " +
        " FROM t_user u ";
}

Right now, it only displays user's middle name on the page. I have a record with the following full name "Sam Andrew Williams". I am only seeing "Andrew" being outputted.

If I were to display this record in correct format, it should be as following:

Williams VII, Sam Andrew

Upvotes: 0

Views: 54

Answers (1)

Gordon Linoff
Gordon Linoff

Reputation: 1269503

I believe the code you want is:

SELECT (u.c_last_name || u.c_suffix || ', ' || u.c_first_name || ' ' || u.c_middle_name) AS userName
FROM t_user u ;

You have commas in your expression between the components, rather than ||. Hence, your query is returning three columns and only the last gets the alias userName (that is why you are getting the middle name).

Note that my habit is to enclose expressions in parentheses. If you had done this, you would have gotten a syntax error because of the comma.

Upvotes: 2

Related Questions