sql query

  • I have got a column with data like 12345 0047225P1

    I need a query to select 0047225 as serial number and select P as account letter.

    Thanks

  • If it is fixed pattern it should work for you.

    DECLARE @STR VARCHAR(100)

    SET @STR = '12345 0047225P1'

    SELECT SUBSTRING(@Str,CHARINDEX(' ',@Str)+1,7) AS ID,

    SUBSTRING(@Str,CHARINDEX(' ',@Str)+8,1) AS 'Account No'

    Shatrughna

  • This was removed by the editor as SPAM

  • cheers mate!

  • I will test and let you know ... Thanks

  • Hello Good Morning...Some of the data is like

    00011 0055500ABC

    So in this Account Number should be 0055500 and Account Letter should be only C

  • so basically i need a query to fetch serial number and letter from the column which has two type of data

    12345 0047225P1

    00011 0055500ABC

    The first data should have serial number = 004722 and letter = P

    The second data should have serial number = 0055500AB and letter = C

  • Duplicate post.

    Replies here please:

    http://www.sqlservercentral.com/Forums/FindPost1228255.aspx

    -- Gianluca Sartori

  • It's not really a duplicate post...

    In this post the account number for "00011 0055500ABC" should be 0055500 whereas in the post Gianluca referenced the expected result is 0055500AB...

    @mario:

    I strongly recommend you first define the expected output instead of asking for different results on different threads related to the very same topic.



    Lutz
    A pessimist is an optimist with experience.

    How to get fast answers to your question[/url]
    How to post performance related questions[/url]
    Links for Tally Table [/url] , Cross Tabs [/url] and Dynamic Cross Tabs [/url], Delimited Split Function[/url]

  • I'm officially confused. :ermm:

    Time for a break.

    -- Gianluca Sartori

Viewing 10 posts - 1 through 9 (of 9 total)

You must be logged in to reply to this topic. Login to reply