467,114 Members | 1,288 Online
Bytes | Developer Community
Ask Question

Home New Posts Topics Members FAQ

Post your question to a community of 467,114 developers. It's quick & easy.

Controlbreak flag in result?

I need a control break flag in my result when a certain value is
different to the previous.

A table/result like this:

PRODUCER ARTICLE
80000 1 <- flag = 1
80000 2 <- flag = 0
80000 3 <- flag = 0
80001 1 <- flag = 1
80001 2 <- flag = 0
80001 3 <- flag = 0

any ideas?

Bernd
Apr 18 '06 #1
  • viewed: 1292
Share:
2 Replies
Ian
Bernd Hohmann wrote:
I need a control break flag in my result when a certain value is
different to the previous.

A table/result like this:

PRODUCER ARTICLE
80000 1 <- flag = 1
80000 2 <- flag = 0
80000 3 <- flag = 0
80001 1 <- flag = 1
80001 2 <- flag = 0
80001 3 <- flag = 0

any ideas?

Bernd


select
producer,
article,
case when rn = 1 then 1 else 0 end as flag
from
(select
producer,
article,
rownumber() over (partition by producer order by article) as rn
from
yourtable) as x;

Apr 18 '06 #2
Ian wrote:
any ideas?


select
producer,
article,
case when rn = 1 then 1 else 0 end as flag
from
(select
producer,
article,
rownumber() over (partition by producer order by article) as rn
from
yourtable) as x;


Thanks a lot. I was able to compress this a little bit into

case when (rownumber() over (partition by producer order by article ))=1
then 1 else 0 end as cbflag

without the additional select (don't know why it works, SQL is sometimes
a mystery to me).

Bernd
Apr 18 '06 #3

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

42 posts views Thread by Shayan | last post: by
2 posts views Thread by Blue Man | last post: by
1 post views Thread by Uri Dimant | last post: by
4 posts views Thread by John Salerno | last post: by
1 post views Thread by Craig Buchanan | last post: by
2 posts views Thread by Efi Merdler | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.