Results 1 to 6 of 6
  1. #1
    Join Date
    Nov 2005
    Posts
    4

    Unanswered: How to get 30 and 31 from this 'Nov2005(30,31)' string

    Hello friends..

    Can anyone tell me how i can get dates that is 30 and 31 from given string like 'Nov2005(30,31)' in sql server.


    date range not fixed in this case ..it may be 1,2,3,4,.... and so on


    Thnx

    Ashish
    Last edited by ashish_kare; 11-28-05 at 08:15.

  2. #2
    Join Date
    Nov 2004
    Location
    on the wrong server
    Posts
    8,835
    Provided Answers: 6
    Go to SQL Server Books Online-->Contents-->Transact SQL Reference and read about CHARINDEX,SUBSTRING, LEFT, RIGHT, REVERSE and the other SQL server string functions. Hint: you are going to have some of them as the arguments for the others.
    “If one brings so much courage to this world the world has to kill them or break them, so of course it kills them. The world breaks every one and afterward many are strong at the broken places. But those that will not break it kills. It kills the very good and the very gentle and the very brave impartially. If you are none of these you can be sure it will kill you too but there will be no special hurry.” Earnest Hemingway, A Farewell To Arms.

  3. #3
    Join Date
    Feb 2004
    Location
    Dublin, Ireland
    Posts
    212
    Code:
    begin
      declare @v varchar(20);
    
      set @v = 'Nov2005(30,31)';
    
      select substring (@v, charindex('(', @v) + 1, charindex(',', @v) - charindex('(', @v) - 1)
    
      select substring (@v, charindex(',', @v) + 1, charindex(')', @v) - charindex(',', @v) - 1)
    
    end

  4. #4
    Join Date
    Nov 2005
    Posts
    4

    I have this solution

    DECLARE @InputString VARCHAR(250)
    DECLARE @TotalLength int
    DECLARE @StartPosition int
    Declare @FormatedString Varchar(250)
    declare @FormatedStringLength int

    SELECT @InputString = 'Nov2005(31,1,2,3,4,5,6)'
    SET @TotalLength = Len(@InputString)
    SET @StartPosition = CHARINDEX( '(', @InputString) + 1
    SET @FormatedString= SUBSTRING(@InputString,@StartPosition,@TotalLength )

    SET @FormatedStringLength= len(@FormatedString) - 1
    SELECT left(@FormatedString,@FormatedStringLength)

  5. #5
    Join Date
    Jun 2003
    Posts
    269

    Thumbs up

    Quote Originally Posted by ashish_kare
    DECLARE @InputString VARCHAR(250)
    DECLARE @TotalLength int
    DECLARE @StartPosition int
    Declare @FormatedString Varchar(250)
    declare @FormatedStringLength int

    SELECT @InputString = 'Nov2005(31,1,2,3,4,5,6)'
    SET @TotalLength = Len(@InputString)
    SET @StartPosition = CHARINDEX( '(', @InputString) + 1
    SET @FormatedString= SUBSTRING(@InputString,@StartPosition,@TotalLength )

    SET @FormatedStringLength= len(@FormatedString) - 1
    SELECT left(@FormatedString,@FormatedStringLength)
    Now u got the string with ',' delimiter.
    Check this link --http://www.sqlteam.com/item.asp?ItemID=2652 for parsing string
    I love cursor,though I never use it.Cos' I dont want to misuse it.
    ----------------------------------------------

    ----cheers
    ----http://mallier.blogspot.com

  6. #6
    Join Date
    Nov 2002
    Location
    Jersey
    Posts
    10,322
    Well since there are never 31 days in November....no

    Read the sticky at the top of the forum and post some info that we can use to figure out what you want....
    Brett
    8-)

    It's a Great Day for America everybody!

    dbforums Yak CorralRadio 'Rita
    dbForums Member List
    I'm Good Once as I ever was

    The physical order of data in a database has no meaning.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •