• p.shabbir (10/25/2013)


    Sean Lange (10/25/2013)


    p.shabbir (10/25/2013)


    Hi Scuby,

    Try this.

    select REPLACE(SUBSTRING(Your_Column,1,CHARINDEX('@',Your_Column)),'@','') Name from Your_Table NOLOCK

    Thanks

    sibi.

    Why NOLOCK???

    Sean,

    At my work i used to specify "NOLOCK" at the end of select statement.Hence, by habit i mentioned there.You can take out that.

    I would suggest that is a habit you learn to break unless you fully understand all the nasty stuff that hint brings to the table.

    http://sqlblogcasts.com/blogs/tonyrogerson/archive/2006/11/10/1280.aspx

    http://blogs.msdn.com/b/davidlean/archive/2009/04/06/sql-server-nolock-hint-other-poor-ideas.aspx

    http://www.jasonstrate.com/2012/06/the-side-effect-of-nolock/[/url]

    And i checked your query.

    Only this is statement is working.

    REPLACE(SUBSTRING(SEmail_Addr,1,CHARINDEX('@',SEmail_Addr)),'@','').

    For other two got this error.

    Error : Invalid length parameter passed to the LEFT or SUBSTRING function.

    That's odd. The code I posted works perfectly. Now if you have email values that don't have an @ it would not work where the find code you posted does. I merely posted a couple of alternative ways. In now way did I mean that your fine code was not sufficient. In fact, I had yours in my list of possibilities.

    _______________________________________________________________

    Need help? Help us help you.

    Read the article at http://www.sqlservercentral.com/articles/Best+Practices/61537/ for best practices on asking questions.

    Need to split a string? Try Jeff Modens splitter http://www.sqlservercentral.com/articles/Tally+Table/72993/.

    Cross Tabs and Pivots, Part 1 – Converting Rows to Columns - http://www.sqlservercentral.com/articles/T-SQL/63681/
    Cross Tabs and Pivots, Part 2 - Dynamic Cross Tabs - http://www.sqlservercentral.com/articles/Crosstab/65048/
    Understanding and Using APPLY (Part 1) - http://www.sqlservercentral.com/articles/APPLY/69953/
    Understanding and Using APPLY (Part 2) - http://www.sqlservercentral.com/articles/APPLY/69954/