473,614 Members | 2,377 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

how to get even or odd number rows from database in db2

1 New Member
hi all,
I was trying to fetch even or odd number rows from database.
currently i am usying DB2 ver 8.0.
any one can help me out.
Jul 27 '07 #1
1 9404
cburnett
57 New Member
Pity you are not on V8.1 where the following would work (change mod()=1 to mod()=0 for even rows):

Expand|Select|Wrap|Line Numbers
  1. select *
  2.   from table(select row_number() over () as rnum, tabschema, tabname 
  3.                from syscat.tables) x
  4.  where mod(rnum,2) = 1
However, if your tables are not too large, try:

Expand|Select|Wrap|Line Numbers
  1. SELECT *
  2.   FROM (SELECT rtrim(t.tabschema) || '.' || t.tabname as key,
  3.                count(*)                               as rnum
  4.           FROM syscat.tables t,
  5.                syscat.tables t1
  6.          where rtrim(t.tabschema) || '.' || t.tabname >=
  7.                rtrim(t1.tabschema) || '.' || t1.tabname
  8.       group by rtrim(t.tabschema) || '.' || t.tabname) as x
  9.  where mod(rnum,2) = 1
Aug 2 '07 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

6
4032
by: PG | last post by:
When deleting a row from the database, that id is now missing. So what I'm trying to do is update in a loop (maybe an sql loop if there is one) of all of the id numbers - sort of like renaming them. It did partly work because all the id's were set to 22. Thats because there was 22 rows. Here's the code I used: $result = mysql_query ("SELECT * FROM counter"); for($counting = 1; $row = mysql_fetch_row ($result); ++$counting)
9
1319
by: Marius Kaizerman | last post by:
I have 5 fields (the number can grow) that represents the stock in different places: stock1, stock2, stock3, stock4, stock5 From a subform, I need to manipulate their values, depending on a rule that is defined using an IF statement. For example: if parent!stores = 1 then stock1=stock1+1 endif
12
3026
by: Martin Heuckeroth | last post by:
Hi Any idea on how to get a row number from the original table? We do a query and get a result. The row number from the result is different from the rownumber of the table the result originated from. I need the record number from the original tabel. How do you get THAT number? Please help, Regards, Martin
7
1832
by: MLH | last post by:
?dcount("","qryOwnrsDueITSwMissingAddr") when run in the immediate window return a number greater than the number of rows that display when the saved query is run - opening in the database window? I consistently see 2 rows in qryOwnrsDueITSwMissingAddr opening with a dbl-clik. Yet ?dcount("","qryOwnrsDueITSwMissingAddr") returns 3 and
4
1755
by: c676228 | last post by:
Hi everyone, I need to write a insruance program which needs to collect multiple people information, The information for each person includes name, email, address, phone, dob etc. The DOB data will be used for calculate premium for each person. and then display total premium quote to the user I had never done that before and not sure, in asp technology what is the easiest way to do. Let's say the user want to enroll 30 people but I...
8
783
by: sqlservernewbie | last post by:
Hi Everyone, Here is a theoretical, and definition question for you. In databases, we have: Relation
4
1328
by: sscoder | last post by:
Hello. I am trying to find information on how to display calculations on the screen using .Net. I am not using a data grid. What I'm trying to do is display how many rows in a database and then do something with that. So for example, in my SQL database I have 345 rows each with an employees info. On the last column is status. 1 = still working and 2 = not working here any more. I would like to display. Number of employees = 345 Number of...
1
7172
by: David Greenberg | last post by:
Hello I am running a DTS (Sql 2000) and transfering data from an SqlServer database to an Ingres database. I am transfering 153k rows. Execution fails with the error message: "The number of failing rows exceeded the maximum specified" The number of rows shouldn't be a problem because in another DTS I copy a lot more rows. Also the width of the row shouldn't be a problem, I'm transfering only 3
1
1841
by: COHENMARVIN | last post by:
I have a gridview and I need to know the number of rows in it. I find the Page_load and the Gridview_Load events are too early to find out the number of rows. I can use the Gridview_databound event to check for the number of rows. But the problem is that the user can update a field on my form, which reduces the number of rows in the gridview, because the gridview SELECT statement no longer finds the records when their flag has been set...
0
8176
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8120
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8620
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8571
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8265
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8423
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
4115
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
1705
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
1420
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.