Results 1 to 3 of 3
  1. #1
    Join Date
    Feb 2002
    Location
    India
    Posts
    38

    Unanswered: Please Help for Function

    Hi
    I am looking for freequently using fuction like Find number of characters in a word.

    Ex:
    [code]
    Declare @Str='AXG00023'
    If I use the function like getnumberofChars(@Str) Then it has to give the result is 3.
    Because rest of all numeric valus.

    Is we have any function like this in SqlServer

    please Help me


    -- Prasad --

  2. #2
    Join Date
    Dec 2001
    Location
    USA
    Posts
    13
    Yes,

    You can use the DATALENGTH(), which will return the number of characters in a string.

    If you are using that on a char datatype, you may want to use a Rtrim() on the field first before getting that datalenght.

    ie. datalength(rtrim(@stringname))

    Scooter Mcfly

  3. #3
    Join Date
    Dec 2001
    Location
    Toronto, Canada
    Posts
    335
    Code:
    DECLARE 
        @Str varchar(50),
        @i int,
        @x int
    
    SET @Str ='AXG00X023'
    SET @i = 0
    SET @x=1
    
    WHILE @x <= DATALENGTH(@Str) BEGIN
        IF ISNUMERIC(SUBSTRING(@Str,@x,1)) = 0
            SET @i=@i+1
    
        SET @x=@x+1
    END
    
    print @i
    If you are using SQL Server 2000 you could put this code into your own user defined function.
    MCDBA

Posting Permissions

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