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
 General SQL Server Forums
 New to SQL Server Programming
 Substring
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

vasu4us
Posting Yak Master

102 Posts

Posted - 09/13/2006 :  12:33:24  Show Profile  Reply with Quote
iam trying to write a string function which will give me the id part of a mail id
but iam geting the string along with @ and when iam trying to remove the last char (@) iam getting error

query:
select substring(leadassignedtombemail,1,(CHARINDEX('@', leadassignedtombemail)))
from lead_details -----> Gives me id along with @


select substring(leadassignedtombemail,1,(CHARINDEX('@', leadassignedtombemail) - 1))
from lead_details ------------>gives me error "Invalid length parameter passed to the substring function."

But
select (CHARINDEX('@', leadassignedtombemail) - 1) from lead_details
works and gives me the length of id without counting @

where did i go wrong

nr
SQLTeam MVY

United Kingdom
12543 Posts

Posted - 09/13/2006 :  12:48:39  Show Profile  Visit nr's Homepage  Reply with Quote
select substring(leadassignedtombemail,1,(CHARINDEX('@', leadassignedtombemail) - 1))
from lead_details
where leadassignedtombemail like '%@%'
or try
where leadassignedtombemail like '_%@%'


you probbaly have some without an @ sign so charindex gives 0.

==========================================
Cursors are useful if you don't know sql.
DTS can be used in a similar way.
Beer is not cold and it isn't fizzy.
Go to Top of Page

vasu4us
Posting Yak Master

102 Posts

Posted - 09/13/2006 :  15:24:44  Show Profile  Reply with Quote
Hay thanks man i just found the same and resolved the problem
the problem was not in the query but in the data, which i was not looking at and was beating around the query.

Thanks
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.09 seconds. Powered By: Snitz Forums 2000