We help IT Professionals succeed at work.

We've partnered with Certified Experts, Carl Webster and Richard Faulkner, to bring you two Citrix podcasts. Learn about 2020 trends and get answers to your biggest Citrix questions!Listen Now

x

sql query with string operation

ramChand123
ramChand123 asked
on
Medium Priority
695 Views
Last Modified: 2013-12-07
i want to write sql query with string operation...

In filed Got First name then space last name.....
i want to select only first name and differenciate by space.
In sql only
Thanks
Comment
Watch Question

flow01IT-specialist
CERTIFIED EXPERT

Commented:
select substr(name,1,instr(name,' ') - 1) first_name from table

what should happen if there is no space ?

select decode instr(name,' '), 0,'No firstname',
                                                   substr(name,1,instr(name,' ') - 1) )  first_name from table

Author

Commented:
in one filed i have

"abc def"

i want only abc only.......

Author

Commented:
i m using firebird

Author

Commented:
in firebird instr and substr is not working
flow01IT-specialist
CERTIFIED EXPERT

Commented:
I don't know of firebird , can you execute the shown sql ? (modified for your table)

Author

Commented:
any firebird expert ?
flow01IT-specialist
CERTIFIED EXPERT

Commented:
substr infirebird =
SUBSTRING(<str> FROM startpos [FOR length])

an equivalent of instr I can't find fast but maybe you know a function firebird to determine the position of a character in a string  (thats what instr does)

Commented:
Try -

SELECT SUBSTRING(name,STRPOS(' ')-1) FROM table

Author

Commented:
sorry but strpos is not working.....
IT-specialist
CERTIFIED EXPERT
Commented:
Is this of any help ?
http://www.volny.cz/iprenosil/interbase/ip_ib_code_string.htm#_code_strpos
Position of substring function in SP

create function POS in the example
SELECT SUBSTRING(name,POS(' ')-1) FROM table

Not the solution you were looking for? Getting a personalized solution is easy.

Ask the Experts
Access more of Experts Exchange with a free account
Thanks for using Experts Exchange.

Create a free account to continue.

Limited access with a free account allows you to:

  • View three pieces of content (articles, solutions, posts, and videos)
  • Ask the experts questions (counted toward content limit)
  • Customize your dashboard and profile

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

OR

Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.