Hello I need help with the following Scenario.
I have the table
Create table Descr_temp(Company_cd Varchar2(10), Company_Name Varchar2(254));
with its data
Insert into descr_temp values ('123', 'ABC SOLUTIONS INC');
Insert into descr_temp values ('546', 'XYZ GLOBAL TECH SOLUTIONS');
Insert into descr_temp values ('923', 'NOWHERE COMPANY INC LTD');
Insert into descr_temp values ('113', 'QSW SOLUTIONS');
I need output to be the 1 word if there are 2 words. and I need first 2 words from the description if there are more than 2 words.
Desired Output:
Company_Cd Company_Name
123 ABC SOLUTIONS
345 XYZ GLOBAL
899 NOWHERE COMPANY
654 QSW
------------------------------------------------------------------------
Hello I need help with the following Scenario.
There is a table with Company Cd, Company Name and All I need is the first 2 words of from the Company name if it has more than 3 words and 1 word if it has 2 words
Example:
Company Cd Company Name
123 ABC SOLUTIONS INC
345 XYZ GLOBAL TECH SOLUTIONS
899 NOWHERE COMPANY INC LTD
654 QSW SOLUTIONS
Desired Output:
Company Cd Company Name
123 ABC SOLUTIONS
345 XYZ GLOBAL
899 NOWHERE COMPANY
654 QSW
please help
THank you for the test case !
SQL> drop table Descr_temp purge;
Table dropped.
SQL> Create table Descr_temp(Company_cd Varchar2(10), Company_Name Varchar2(254));
Table created.
SQL>
SQL>
SQL> Insert into descr_temp values ('123', 'ABC SOLUTIONS INC');
1 row created.
SQL> Insert into descr_temp values ('546', 'XYZ GLOBAL TECH SOLUTIONS');
1 row created.
SQL> Insert into descr_temp values ('923', 'NOWHERE COMPANY INC LTD');
1 row created.
SQL> Insert into descr_temp values ('113', 'QSW SOLUTIONS');
1 row created.
SQL> Insert into descr_temp values ('113', 'ONE_WORD_COMPANY');
1 row created.
SQL>
SQL>
SQL> col company_short_name format a40
SQL> select
2 company_cd,
3 case
4 when instr(Company_Name,' ',1,2) > 0 then substr(Company_Name,1,instr(Company_Name,' ',1,2)-1)
5 when instr(Company_Name,' ',1,1) > 0 then substr(Company_Name,1,instr(Company_Name,' ',1,1)-1)
6 else Company_Name
7 end company_short_name
8 from Descr_temp;
COMPANY_CD COMPANY_SHORT_NAME
---------- ----------------------------------------
123 ABC SOLUTIONS
546 XYZ GLOBAL
923 NOWHERE COMPANY
113 QSW
113 ONE_WORD_COMPANY
5 rows selected.
SQL>
SQL>
SQL>