473,434 Members | 1,389 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,434 software developers and data experts.

Display records sequentially without repetition

I want that each time i execute query it display records in a way that the top record will be positioned last and so on.
First time when i executed query it will display like this
name
A
B
C
D
second time
name
B
C
D
A
third time
name
C
D
A
B
fourth time
name
D
A
B
C
fifth time
A
B
C
D and so on
Sep 15 '10 #1
8 3380
NeoPa
32,556 Expert Mod 16PB
Without getting into the realms of pretty complicated programming where the data is manipulated every time (in other words this could not be triggered simply by the execution of a query), this is not possible.
Sep 15 '10 #2
ck9663
2,878 Expert 2GB
May I know what you will need this for?

~~ CK
Sep 15 '10 #3
i am working on search engine. I want this to rotate search results. A same user can see records sequentially that the last record will not be served at the top and so on. I have use random function but it does't solve the purpose.
Sep 16 '10 #4
NeoPa
32,556 Expert Mod 16PB
I would suggest a UDF (User-Defined Function) that returns a Cursor or Table and that maintains the position in the file by saving something to a table every time it's run. Your question is too non-specific to go into much more detail with it.
Sep 16 '10 #5
ck9663
2,878 Expert 2GB
RAND() function returns the same value within the same query. If you just need to randomize the returned records, read this.

Good Luck!!!

~~ CK
Sep 16 '10 #6
Possibly add a column to the table with an integer defined, and assign identity to the field, then remove it (just to number it once) - and each time you run the query (and order by that integer) - you can take the min(integer) and make it max(integer)+1, and just to make sure you don't go over the 65535 (or whatever size # you assign) - perhaps do an update table set integer = integer -1 at the end.
Sep 16 '10 #7
NeoPa
32,556 Expert Mod 16PB
If you are talking about some form of search query (as opposed to simpler stored data), and I imagine you must be if you are working on a Search process, then I cannot see any practical way that the data would even be available to process.

To order data in a special way you at least need to be able to define what that is in terms of data, or information, that is available. If I understand correctly what you're after, then I can't see that you even have any such information available. A search run has no access to information pertaining to any previous run of that same search, and unless you propose to save such information per search (in most cases highly impractical), then I see no way that this could be achieved.

Does this make sense to you?
Sep 17 '10 #8
Example of concept posted above:

Expand|Select|Wrap|Line Numbers
  1. drop table dummy
  2. go
  3.  
  4. CREATE TABLE dummy
  5. (
  6.     thetext varchar(10)
  7. )
  8.  
  9. go
  10.  
  11. insert into dummy values ('ABDC')
  12. insert into dummy values ('CDEF')
  13. insert into dummy values ('EFGH')
  14. insert into dummy values ('HIJK')
  15. insert into dummy values ('LMNO')
  16. insert into dummy values ('PQRS')
  17. insert into dummy values ('TUVW')
  18.  
  19. alter table dummy
  20. add theidentity int identity(1,1)
  21. , theid int
  22. go
  23.  
  24. update dummy
  25. set theid = theidentity
  26. go
  27.  
  28. alter table dummy
  29. drop column theidentity
  30. go
  31.  
  32. select * from dummy
  33. thetext    theid
  34. ABDC    1
  35. CDEF    2
  36. EFGH    3
  37. HIJK    4
  38. LMNO    5
  39. PQRS    6
  40. TUVW    7
  41.  
  42.  
Then the stored proc:
Expand|Select|Wrap|Line Numbers
  1. create procedure dbo.sp_BottomBump (@tblname varchar(100))
  2.  
  3. as
  4.  
  5. BEGIN
  6.  
  7. DECLARE @Query varchar(8000)
  8. DECLARE @Query2 varchar(8000)
  9. SET @Query = 'SELECT * FROM ' + @tblname + ' order by theid'
  10.  
  11.  
  12.  
  13. SET @query2 = 'update ' + @tblname + '
  14. set theid = (select max(theid) from ' + @tblname + ') + 1
  15. where theid = (select min(theid) from ' + @tblname + ')'
  16.  
  17. exec (@query2)
  18.  
  19. SET @query2 = 'update ' + @tblname + '
  20. set theid = theid - 1'
  21.  
  22. exec (@query2)
  23.  
  24. exec(@query)
  25.  
  26. end
  27.  
  28. go
  29.  
And then the results:
Expand|Select|Wrap|Line Numbers
  1. exec sp_BottomBump 'dummy'
  2. thetext    theid
  3. CDEF    1
  4. EFGH    2
  5. HIJK    3
  6. LMNO    4
  7. PQRS    5
  8. TUVW    6
  9. ABDC    7
  10.  
  11. exec sp_BottomBump 'dummy'
  12. thetext    theid
  13. EFGH    1
  14. HIJK    2
  15. LMNO    3
  16. PQRS    4
  17. TUVW    5
  18. ABDC    6
  19. CDEF    7
  20.  
  21.  
  22. thetext    theid
  23. HIJK    1
  24. LMNO    2
  25. PQRS    3
  26. TUVW    4
  27. ABDC    5
  28. CDEF    6
  29. EFGH    7
  30.  
Sep 17 '10 #9

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

Similar topics

3
by: Daniel Tan | last post by:
Hi, i got a subform and inside got some records. But i want to press a button and make all those records to a report. It only display all those records with same Job Order no. I want to display all...
2
by: yoshitha | last post by:
hi, i want to display records in datagrid. strtestids() is a string array. it contains some testids. based on these ids i've to fill the datagrid. i wrote code like this
1
by: Kas_aspnet | last post by:
Hi, I have to display a sequence of records in an Aspx page. The problem is, i have to display the records by checking conditions like Classic ASP. For example, consider an employee table. In...
0
by: Tony | last post by:
vs 2002 - vb - access 2002 - xp - web forms I want to display records, one at a time. I have about 25 fields to display. I've created SQL and retrieved records. I placed data in 25 separate...
3
by: Kai Zhang | last post by:
I am trying to display some database records in datagrid using dataset. the records need to be displayed are couple of thousands, but the records in database that the SQL query needs to exam are...
3
by: qilinw | last post by:
In a winform I want to display database records using datagrid, with dataset for a couple of thousands records it seems very slow. I have read an article in group...
3
by: Bob Sanderson | last post by:
I am trying to create a form for a MySQL database similar to a spreadsheet. The idea is to display a list of records, with the last line of the list being an input form. When the user enters data...
5
by: dorandoran | last post by:
How do I display records using object oriented method? All I have the link to their api help http://www.e-topco.com/oa/oa_help/OpenAir_SOAP.htm and few example. I am want display all the...
2
by: kurtzky | last post by:
i created a form that should function as follows: i will enter a number in a textbox..then it should query from the database all the records which has that number..these records will have a...
1
by: sanchezl | last post by:
Hi, I am developing a program in visual basic that extracts info from an access database. So far I know how to add records, make a query and count the number of records that that query gives, but...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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,...
0
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...
1
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...
0
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...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?

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.