One row at a time from a database table
Database
2
Posts
2
Posters
0
Views
1
Watching
-
I want to display one row at a time on a gridview from my database table, where i'll be selecting the row by its primary key randomly and some condition using sql server 2005. please help.
ML Lingwati
Hi, if I have understood your problem, then you have a table say tblRecords with key(int, PK) and Value(varchar). Like Key Value ----------------- 1 Value1 2 Value2 3 Value3 4 Value4 ................ ................. [n] Value[n], where n = any positive number Now if you fire the following query, it will select only 1 record randomly.
SELECT *
FROM dbo.tblRecords
WHERE [Key] = CAST(RAND()*10 AS INT)Note- If you have values between 1 to 1000, then it will be RAND()*1000 hope this helps. Please let me know in case of any concern :)
Niladri Biswas