Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

SQL How to add parentheses to output data

Tags:

sql

For a college assignment I need to show the last column of output data in parentheses as shown below.

My current query is:

SELECT
SUBSTRING(FirstName,1,1) AS '',
'.' AS '',
LastName AS '', UPPER(Title) AS '' 
FROM employees
WHERE (Title != 'Sales Representative');

This query shows the output as:

B . Brown    STOREMAN
C . Carr     RECEPTIONIST
D . Dig      DRIVER

I need it to show:

B . Brown    (STOREMAN)
C . Carr     (RECEPTIONIST)
D . Dig      (DRIVER)
like image 569
user2709963 Avatar asked Aug 24 '13 02:08

user2709963


1 Answers

You should be able to do this using the CONCAT function

SELECT
SUBSTRING(FirstName,1,1) AS '',
'.' AS'',
LastName AS '', CONCAT('(',UPPER(Title),')') AS '' 
FROM employees
WHERE (Title !='Sales Representative');
like image 73
Dan Drews Avatar answered Oct 16 '22 12:10

Dan Drews