Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
Discussion Groups
Database Servers
DB2InformixIngresMS SQLOraclePervasive.SQLPostgreSQLProgressSybase
Desktop Databases
FileMakerFoxProMS AccessParadox
General
General DB TopicsDatabase Theory
Related Topics
Java Development.NET DevelopmentVB DevelopmentMore Topics ...

Database Forum / DB2 Topics / April 2006

Tip: Looking for answers? Try searching our database.

Controlbreak flag in result?

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Bernd Hohmann - 18 Apr 2006 12:04 GMT
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
Ian - 18 Apr 2006 12:23 GMT
> I need a control break flag in my result when a certain value is
> different to the previous.
[quoted text clipped - 12 lines]
>
> 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;
Bernd Hohmann - 18 Apr 2006 12:44 GMT
>> any ideas?
>
[quoted text clipped - 9 lines]
>      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
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2009 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.