I have data in one column called first name in this format " ANNETTE W * LOW "
i want to make another column called Last name and put all the data in last name after *
input is first name
ANNETTE W * LOW
out put required :
first name last name
ANNETTE W LOW
request a sql query please
r937
August 30, 2018, 6:36pm
2
please identify which platform youāre on
functions can differ from one to the next
I use oracle sql developer
r937
August 30, 2018, 6:56pm
4
SELECT SUBSTRING(column FROM 1 FOR LOCATE(column,'*')-1) AS first_name
, SUBSTRING(column FROM LOCATE(column,'*')+1) AS last_name
1 Like
Thanks for query .
how this will add a column and implement the change in entire column .
iām using oracle sql developer. where in my emp table i have data in column called name as
ANNETTE W * LOW now i need to carete new column called last name and split data staring after *
now can you please share the query
You have the query for returning āfirst_nameā and ālast_nameā. Canāt you simply use that for an INSERT / UPDATE into the new table / fields?
Thanks for your reply .
which query are you referring too ?
The one that was handed to you:
SELECT SUBSTRING(column FROM 1 FOR LOCATE(column,'*')-1) AS first_name
, SUBSTRING(column FROM LOCATE(column,'*')+1) AS last_name
Did you try running that to see if it does what you want it to?
no this query is not working in sql
⦠did you replace ācolumnā with your column name?
really why will i keep column like this . yes i changed
What error message(s) did you get?
rpkamp
August 30, 2018, 9:04pm
13
Well, if we got a dollar for every time somebody copy/pasted a piece of code blindly and then complains it doesnāt work⦠Letās just say we wouldnāt be on these forums anymore.
Nothing personal. Itās just it can be a bit frustrating at times is all.
Good on you for not being one of those people
2 Likes
r937
August 30, 2018, 9:35pm
14
did you include a FROM clause?
Thanks R937, apologies if i mentioned it wrongly iām using microsoft sql server studio and the query iām using is
update test set
first_name = rtrim(substring(first_name, 1, instr(first_name, '*') - 1)),
last_name = ltrim(substring (first_name, instr(first_name, '*') + 1));
However, it giving me error saying that substring can only 3 arguments.please help
r937
August 31, 2018, 6:36am
16
that is the biggest, hugest, most astonishing typo iāve ever seen ā somehow trying to type āmicrosoft sql server studioā and all of a sudden āoracle sql developerā accidentally pops out
so i showed you how to do it with oracle syntax
now all you have to do is come up with the exact same idea using sql server functions
hint: look up SUBSTRING in the sql server manual for instructions on the 3 parameters you need
4 Likes
system
Closed
November 30, 2018, 1:36pm
17
This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.