Re: Puzzle: What should this query return?

From: Steve Kass <skass_at_drew.edu>
Date: Fri, 28 Jun 2002 17:05:07 -0400
Message-ID: <3D1CCF83.2B0E8903_at_drew.edu>


Ivan,

The 1=0 alone doesn't always exclude results, since

  select count(*) from T where 1=0

should return one row, and the puzzle is that the case expression includes a count() expression as one alternative (of course not one that happens here).

Steve

Ivan Demkovitch wrote:

> I think it shouldn't return anything since we have Where 1=0
>
> X
> --
>
> (0) Rows affected
>
> "Steve Kass" <skass_at_drew.edu> wrote in message
> news:3D1CC3BC.203279AC_at_drew.edu...
> > What should this query return, assuming T contains one row?
> >
> > select case when 1=1 then 12 else count(0) end as X from T where 1=0
> >
> > SQL Server says:
> >
> > X
> > --
> > 12
> >
> > Ocelot says:
> > [OCELOT][OCELOT]CLI specific: Overflow while allocating RC, table size =
> <768> stmt count = <51>
> >
> > Similar query:
> >
> > select case when 1=0 then 12 else 1+count(0) end as X from T where 1=0
> >
> > SQL Server says:
> >
> > X
> > --
> > 1
> >
> > Ocelot says:
> >
> > X
> > --
> > 0
> >
> > What does the standard say?
> >
> > Steve Kass
> > Drew University
> >
Received on Fri Jun 28 2002 - 23:05:07 CEST

Original text of this message