Hi,
In a DB2 Table, say Employee, I need to replace only second character with # in the first name. How to do that?
Can someone please help with this question. I was not able to understand that question and could not answer it.
Replace Only second character with # in the name.
-
- New Member
- Posts: 1
- Joined: Wed Dec 17, 2014 12:18 pm
- Robert Sample
- Global Moderator
- Posts: 1895
- Joined: Fri Jun 28, 2013 1:22 am
- Location: Dubuque Iowa
Re: Replace Only second character with # in the name.
This may have been a question to determine your problem-solving techniques, or it may have been a question to check your knowledge of DB2 functions. Questions that would need to be answered include:
- Is first name a column in the table?
- If not, is the employee name in first name last name order or last name, first name order?
Depending on the answers to these questions, you should have mentioned SUBSTR and LOCATE functions.
- Is first name a column in the table?
- If not, is the employee name in first name last name order or last name, first name order?
Depending on the answers to these questions, you should have mentioned SUBSTR and LOCATE functions.
- Anuj Dhawan
- Founder
- Posts: 2802
- Joined: Sun Apr 21, 2013 7:40 pm
- Location: Mumbai, India
- Contact:
Re: Replace Only second character with # in the name.
Assuming EMP_NAME is the column for first name, this should help:
where EMPLOYEE is the table name.
Code: Select all
SELECT EMP_NAME,SUBSTR(ENAME,1,1)||'#'||SUBSTR(EMP_NAME,3,LENGTH(EMP_NAME)) FROM EMPLOYEE;
where EMPLOYEE is the table name.
Thanks,
Anuj
Disclaimer: My comments on this website are my own and do not represent the opinions or suggestions of any other person or business entity, in any way.
Anuj
Disclaimer: My comments on this website are my own and do not represent the opinions or suggestions of any other person or business entity, in any way.
Create an account or sign in to join the discussion
You need to be a member in order to post a reply
Create an account
Not a member? register to join our community
Members can start their own topics & subscribe to topics
It’s free and only takes a minute