Home All Groups Group Topic Archive Search About

Re: SQL Bug: Column Value/Identity

Author
8 Sep 2005 8:59 PM
Scott Abel
I have encountered the same problem, and installed SP4 to try to get the fix.
However, the problem still occurs.  My workaround is to change the order of
the parameters.   I was using the same UDF in a select list twice, and the
only difference was the value of the third parameter.  By changing the
parameters around so that the third parameter is now the first parameter, the
problem goes away.

The article says that this fix is in SP4, so I'm wondering if the hotfix
just didn't make it into the release, or if it doesn't fix all variants of
the bug.

The repro below is a function that parses out delimted strings (such as an
Area Code and Phone number that are delimited by a '-' character)

repro (use Northwind DB):
--------------------------------
-- 1. create function

CREATE  FUNCTION dbo.Piece ( @CharacterExpression VARCHAR(8000), @Delimiter
CHAR(1), @Position INTEGER )
RETURNS VARCHAR(8000)
AS
BEGIN

    If @Position<1
        return null
    if len(@Delimiter)<>1
        return null

    declare @Start integer

    set @Start=1

    while @Position>1
    BEGIN
        Set @Start=ISNULL(CHARINDEX(@Delimiter, @CharacterExpression, @Start),0)

        IF @Start=0
            return null

        set @position= @position-1

        set @Start=@Start+1

    END

    Declare @End INTEGER

    Set @End= ISNULL(CHARINDEX(@Delimiter, @CharacterExpression, @Start),0)

    If @End=0
        Set @End=LEN(@CharacterExpression)+1

    RETURN SUBSTRING(@CharacterExpression, @Start, @End-@Start)

END

--2.  use UDF twice on select list. Adding "group by" causes it to return
first
--value twice, instead of first and second values

select dbo.Piece(Phone, '-', 1), dbo.Piece(Phone, '-', 2)
from Customers
--group by dbo.Piece(Phone, '-', 1), dbo.Piece(Phone, '-', 2)
order by 1, 2




Show quote
"Razvan Socol" wrote:

> I recently found out that Microsoft has added a new KB article for this
> issue:
> http://support.microsoft.com/?kbid=883415
>
> The good news is that there is a hotfix, the bad news is that it isn't
> publicly available. To get it, you have to open a paid support incident
> with Microsoft and if they find out that the hotfix is the solution in
> your case, you will get your money back.
>
> Razvan
>
> PS. Here's a funny thing: although Microsoft knew about this problem at
> least since Octomber 3, 2003 (the last reviewed date of KB article
> 323504), they fixed it on July 22, 2004 (the date of the sqlservr.exe
> file from the hotfix in KB article 883415). That's just two weeks after
> Steve Kass reported the bug to Microsoft again, with a clear repro. But
> they didn't publish an article about the hotfix until December 15, 2004
> (the last reviewed date of KB article 883415) and I only found out
> about this today, from the Technet Flash issued on January 5, 2005.
>
>

Author
14 Sep 2005 8:05 PM
Razvan Socol
Quote from KB article 883415:
  To resolve this problem, you must install this hotfix AND TURN ON
  TRACE FLAG 9056. You can turn on trace flag 9056 by adding -T9056
  to the SQL Server command line [...]

There are many trace flags that must be turned on in order for some
bugs to be fixed. I don't think it's a good idea for Microsoft to
require all those trace flags to be turned on, instead of correcting
the default behaviour of SQL Server. I've written a small list of such
obscure trace flags in the following message:
http://groups.google.com/group/microsoft.public.sqlserver.programming/msg/04b7d1e65df64435

Razvan
Author
15 Sep 2005 5:05 PM
Scott Abel
I read the article that you referenced, thanks for your feedback on this. 
However, I am still confused as to why a trace flag setting would be required
for a fix that is in SP4.  This is NOT a hotfix that we're talking about, it
is listed as fixed in SP4.

I can see why MS might be gun-shy about making a hotfix change some other
default behaviors, but once the fix is in a service pack release it should be
turned on by default, right?

Show quote
"Razvan Socol" wrote:

> Quote from KB article 883415:
>   To resolve this problem, you must install this hotfix AND TURN ON
>   TRACE FLAG 9056. You can turn on trace flag 9056 by adding -T9056
>   to the SQL Server command line [...]
>
> There are many trace flags that must be turned on in order for some
> bugs to be fixed. I don't think it's a good idea for Microsoft to
> require all those trace flags to be turned on, instead of correcting
> the default behaviour of SQL Server. I've written a small list of such
> obscure trace flags in the following message:
> http://groups.google.com/group/microsoft.public.sqlserver.programming/msg/04b7d1e65df64435
>
> Razvan
>
>

AddThis Social Bookmark Button