DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

+ Reply to Thread
Results 1 to 7 of 7
  1. #1
    pm Guest

    Counting character in a column value


    Anybody know, How can we count a character in a column value

  2. #2
    DaveSatz Guest

    Re: Counting character in a column value

    at least in 7 you would need to loop through the column value using
    CHARINDEX and set a variable to increment for each occurence.

    --
    HTH,
    David Satz
    Principal Software Engineer
    Hyperion Solutions
    ->Using SQL Server 7.0 SP3/6.5 SP5a/Cold Fusion 4.5.1 SP2/VSS
    (Please reply to group only - emails answered rarely)
    -----------------------------------------------------------------
    "pm" <pmsep2000@hotmail.com> wrote in message
    news:3b3ca5fc$1@news.devx.com...
    >
    > Anybody know, How can we count a character in a column value




  3. #3
    Zara Guest

    Re: Counting character in a column value


    T-SQL: Len(string)

    Dan Vernet

    "pm" <pmsep2000@hotmail.com> wrote:
    >
    >Anybody know, How can we count a character in a column value



  4. #4
    DaveSatz Guest

    Re: Counting character in a column value

    I assume pm meant to count the occurence of a character (or expression)
    within a character-type column ???

    "Zara" <dvernet@kos.net> wrote in message news:3b3cc3f2$1@news.devx.com...
    >
    > T-SQL: Len(string)
    >
    > Dan Vernet
    >
    > "pm" <pmsep2000@hotmail.com> wrote:
    > >
    > >Anybody know, How can we count a character in a column value

    >




  5. #5
    pm Guest

    Re: Counting character in a column value


    you are right Dave.
    But How can I do it store proc dynamically?


    "DaveSatz" <davidsatz@yahoo.com> wrote:
    >I assume pm meant to count the occurence of a character (or expression)
    >within a character-type column ???
    >
    >"Zara" <dvernet@kos.net> wrote in message news:3b3cc3f2$1@news.devx.com...
    >>
    >> T-SQL: Len(string)
    >>
    >> Dan Vernet
    >>
    >> "pm" <pmsep2000@hotmail.com> wrote:
    >> >
    >> >Anybody know, How can we count a character in a column value

    >>

    >
    >



  6. #6
    DaveSatz Guest

    Re: Counting character in a column value

    something like:

    DECLARE @Str varchar(30 )
    , @LookFor char(1)
    ,@Occurences int
    ,@Pos int
    ,@newPos int

    SET @Str = 'abc.07/07/2000*x?'
    SET @LookFor = "0" -- "/"
    SET @Occurences = 0

    SET @Pos = CHARINDEX( @LookFor , @Str )
    WHILE @Pos > 0
    BEGIN
    SET @Occurences = @Occurences + 1
    SET @NewPos = @Pos+1
    SET @Pos = CHARINDEX( @LookFor , @Str, @NewPos )
    END

    SELECT @Occurences
    GO



    "pm" <pmsep2000@hotmail.com> wrote in message
    news:3b3ce15b$1@news.devx.com...
    >
    > you are right Dave.
    > But How can I do it store proc dynamically?
    >
    >
    > "DaveSatz" <davidsatz@yahoo.com> wrote:
    > >I assume pm meant to count the occurence of a character (or expression)
    > >within a character-type column ???
    > >
    > >"Zara" <dvernet@kos.net> wrote in message

    news:3b3cc3f2$1@news.devx.com...
    > >>
    > >> T-SQL: Len(string)
    > >>
    > >> Dan Vernet
    > >>
    > >> "pm" <pmsep2000@hotmail.com> wrote:
    > >> >
    > >> >Anybody know, How can we count a character in a column value
    > >>

    > >
    > >

    >




  7. #7
    JC Guest

    Re: Counting character in a column value



    hi!

    there's a system function 'Len', this will give you the number of characters,
    including spaces.

    JC

    "pm" <pmsep2000@hotmail.com> wrote:
    >
    >Anybody know, How can we count a character in a column value



Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
HTML5 Development Center
 
 
FAQ
Latest Articles
Java
.NET
XML
Database
Enterprise
Questions? Contact us.
C++
Web Development
Wireless
Latest Tips
Open Source


Top DevX Stories

Easy Web Services with SQL Server 2005 HTTP Endpoints
JavaOne 2005: Java Platform Roadmap Focuses on Ease of Development, Sun Focuses on the "Free" in F.O.S.S.
Wed Yourself to UML with the Power of Associations
Microsoft to Add AJAX Capabilities to ASP.NET
IBM's Cloudscape Versus MySQL


Sponsored Links