UDF does not work in SELECT statement

  • I'll try that.

    Thanks!

  • I assume that your data has a very specific structure to it.  As Sergy pointed out, the test IF @Counter > 0 is meaningless, as it will always be true.

    One thing - your WHILE loop has a bug in it. It only works because you chose to declare @TestChar as type CHAR, which will make the test for a space (asc 32) true. If you changed it to VARCHAR you'll get arithmetic overflow error.  I wouldn't depend on side effects like that for my code to run correctly.

    I would change your original code:

         SET @TestChar = SUBSTRING(@Result, @Counter, 1)

         WHILE @Found = 0

           BEGIN

             --If the character is a tab, CR, LF, or space, then we have gotten

             --to the end of the quote number and can break out of the loop

             IF ASCII(@TestChar) IN (10, 13, 9, 32)

               SET @Found = 1

             SET @Counter = @Counter + 1

             SET @TestChar = SUBSTRING(@Result, @Counter, 1)

           END

    to this:

         WHILE @Counter <= Len(@Result)

           BEGIN

             SET @TestChar = SUBSTRING(@Result, @Counter, 1)

             --If the character is a tab, CR, LF, or space, then we have gotten

             --to the end of the quote number and can break out of the loop

             IF ASCII(@TestChar) IN (10, 13, 9, 32)

               BREAK

             SET @Counter = @Counter + 1

           END

  • I will try it.

    You guys are good.  I have a lot to learn.

    Thanks- to all.

Viewing 3 posts - 16 through 17 (of 17 total)

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