Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.databases.ms-sqlserver > #695

Re: SQL help

From Lennart Jonsson <erik.lennart.jonsson@gmail.com>
Newsgroups comp.databases.ms-sqlserver, microsoft.public.sqlserver.programming
Subject Re: SQL help
Date 2011-09-30 21:39 +0200
Organization A noiseless patient Spider
Message-ID <j655ug$uv3$1@dont-email.me> (permalink)
References <j653m9$84v$1@speranza.aioe.org>

Cross-posted to 2 groups.

Show all headers | View raw


On 2011-09-30 21:01, Phil Hunt wrote:
>   Table2 ID Status
>       789 4
>       789 4
>       1374
> 
>       1374
> 
>       1374
> 
>       1940 15
>       1940 15
>       1940 15
> 
> 
> I want to Select the above to output the followng
> 
> 789    0
> 1374   0
> 1940    1 (because it has Status of 15)
> 
> 
> I have been staring at this so long, my head and eye hurts. Can someone help 
> ?
> 

I assume there is a good reason for the design of this table. Something
like:

select id, max(case when status = 15 then 1 else 0 end)
from t2
group by id

will do.


/Lennart

Back to comp.databases.ms-sqlserver | Previous | NextPrevious in thread | Next in thread | Find similar


Thread

SQL help "Phil Hunt" <aaa@aaa.com> - 2011-09-30 15:01 -0400
  Re: SQL help Hugo Kornelis <hugo@perFact.REMOVETHIS.info.INVALID> - 2011-09-30 21:34 +0200
  Re: SQL help Lennart Jonsson <erik.lennart.jonsson@gmail.com> - 2011-09-30 21:39 +0200
    Re: SQL help "Phil Hunt" <aaa@aaa.com> - 2011-09-30 15:43 -0400

csiph-web