By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
437,558 Members | 1,068 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 437,558 IT Pros & Developers. It's quick & easy.

Controlbreak flag in result?

P: n/a
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
Share this Question
Share on Google+
2 Replies


P: n/a
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

P: n/a
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.