SQL Server Forums
Profile | Register | Active Topics | Members | Search | Forum FAQ
 
Register Now and get your question answered!
Username:
Password:
Save Password
Forgot your Password?

 All Forums
 SQL Server 2008 Forums
 Transact-SQL (2008)
 how to pick string from special characters
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

mohan123
Posting Yak Master

India
199 Posts

Posted - 12/20/2012 :  08:34:12  Show Profile  Reply with Quote
hello all,

i have problem with string picking issue

like chaitanya@yahoo.com in that one i need to pick first 3 characters and rest after @ like my output is cha@yahoo.com

i have written query like this

select SUBSTRING('chaitanya@symphonycorp.com',1,3)+'@'+Substring('chaitanya@symphonycorp.com',charindex('@','chaitanya@symphonycorp.com')+1,LEN('chaitanya@symphonycorp.com')) and output is coming fine

but here i used 2 substring conditions and concatenated.How can i pull in single statement without concatenating

P.V.P.MOhan

DonAtWork
Flowing Fount of Yak Knowledge

2111 Posts

Posted - 12/20/2012 :  08:43:29  Show Profile  Reply with Quote
whats wrong with concatenating?








How to ask: http://weblogs.sqlteam.com/brettk/archive/2005/05/25/5276.aspx

Go to Top of Page

bandi
Flowing Fount of Yak Knowledge

India
1437 Posts

Posted - 12/20/2012 :  08:49:01  Show Profile  Reply with Quote
See this....
DECLARE @str varchar(100)= 'chaitanya@symphonycorp.com'
SELECT REPLACE (@str, SUBSTRING (@str, 4, charindex('@', @str, 4)-4), '')

--
Chandu
Go to Top of Page

jimf
Flowing Fount of Yak Knowledge

USA
2868 Posts

Posted - 12/20/2012 :  09:02:34  Show Profile  Reply with Quote
Same result as bandi, just different method with less purple words
stuff(@str,4,patindex('%@%',@str)-4,'')

Jim

Everyday I learn something that somebody else already knew
Go to Top of Page

mohan123
Posting Yak Master

India
199 Posts

Posted - 12/20/2012 :  09:53:20  Show Profile  Reply with Quote
yeah thanks a lot dude

P.V.P.MOhan
Go to Top of Page

Bustaz Kool
Flowing Fount of Yak Knowledge

USA
1430 Posts

Posted - 12/20/2012 :  17:57:42  Show Profile  Reply with Quote
I don't think this works if the preamble is shorter than three characters.

=================================================
Hear the sledges with the bells - silver bells!
What a world of merriment their melody foretells!
Go to Top of Page

bandi
Flowing Fount of Yak Knowledge

India
1437 Posts

Posted - 12/21/2012 :  00:31:09  Show Profile  Reply with Quote
quote:
Originally posted by mohan123

yeah thanks a lot dude
P.V.P.MOhan


Welcome

--
Chandu
Go to Top of Page
  Previous Topic Topic Next Topic  
 New Topic  Reply to Topic
 Printer Friendly
Jump To:
SQL Server Forums © 2000-2009 SQLTeam Publishing, LLC Go To Top Of Page
This page was generated in 0.08 seconds. Powered By: Snitz Forums 2000