4

I'm trying to join two columns together with a space separated and the first column requiring a SUBSTR and the other not. I have written this query:

SELECT CONCAT(SUBSTR(FIRST_NAME,1,1), ' ',LAST_NAME) AS NAME
FROM OEHR_EMPLOYEES;

However I have tried numerous searching online and tried different ways to get it to work and I cannot. I get numerous errors. The result I am trying to get is for example if the raw data was Ray Adams then the result would be R Adams. Any help would be appreciated.

0

4 Answers 4

10

Use Concatenation Operator:

SELECT SUBSTR(FIRST_NAME,1,1)|| ' '||LAST_NAME AS NAME FROM OEHR_EMPLOYEES;

Or nested concat function:

SELECT concat(CONCAT(SUBSTR(FIRST_NAME,1,1), ' '),LAST_NAME) AS NAME FROM OEHR_EMPLOYEES;
Sign up to request clarification or add additional context in comments.

1 Comment

Great thanks for your help they both worked perfectly
2

CONCAT only allows you to concatenate 2 strings together, not more. You should use:

SELECT CONCAT(CONCAT(SUBSTR(FIRST_NAME,1,1), ' '),LAST_NAME) AS NAME FROM OEHR_EMPLOYEES;

Comments

2

Try this:

SELECT FIRST_NAME|| ' '||LAST_NAME AS FULL_NAME

1 Comment

Please explain what your solution does.
0
SELECT CONCAT(FIRST_NAME||' ',LAST_NAME) AS Name FROM EMPLOYEES;

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.