SQL Server :: Select Random If Multiple Rows Are The Same
Oct 25, 2010
i have a select statement which returns a column value.
id like to display the lowest column value there is, but if there are multiple rows with the same (and lowest) value id like it to be random which one of the rows is selected.. how would i do this? my select statement is currently:
SELECT TOP (1) url, ABS(r1 - @r1) + ABS(r2 - @r2) AS difference
FROM type
ORDER BY difference
this picks the one lowest result for me, but if there are multiple duplicate lowest results id like to select them, and show one at random..?
View 6 Replies
Similar Messages:
Dec 29, 2010
I am working on a project for a market research company that needs to select and have it displayed to my gridview. I need a select statement that will randomly put on my gridview the following:
Recruitment Goal 21 people and out of those people 10 people have to be male, 11 people female, 9 of them white, 9 of them black, 2 of them hispanic. Is there a way I could do that? I was thinking of doing a stored procedure and doing something like
Select TOP 10 * from Canidates where sex = 'Male' order by newid() Into #tmp
Select TOP 11 * from Canidates where sex = 'Female' order by newid() Into #tmp
Etc... and then just selecting from the Temp Table.
View 10 Replies
Sep 27, 2010
I want to return random records in term of time whithout NEWID
View 5 Replies
Sep 3, 2010
i have a query that select random records in access database in terms of time : "SELECT TOP 10 * FROM Tbl ORDER BY Rnd(-10000000*TimeValue(Now())*[ID])" now i wish to convert this query for using in sql server 2005 such that return random records in term of time
View 5 Replies
Nov 17, 2010
trying to write a stored procedure to select any 5 random columns from a selected row,this is the query i ve written so far
[Code]....
[Code]....
View 8 Replies
Aug 18, 2010
I was looking for such an SQL query that it will give me the first 20 records but it will skip the first 10
There are some LIMIT and OFFSET stuff with MySQL and Postgres but what works with SQL Server?
View 2 Replies
Jul 20, 2010
I want to select many rows from my SQL Server database and combine them in a certain manner. Currently, I've been using the following method to get these rows:
[code]....
View 1 Replies
Oct 11, 2010
I have a list box that allows for multiple selections (holding down the control key) the selection quantity is basically unlimited, but realistically should never be more than 50 to 100 items from the listing of about 3000 items.
I need to collect the list of selected items from the drop down list and retrieve each of their full records from the item master and populate a gridview.
View 3 Replies
Aug 31, 2010
Is it possible to select multiple gridview rows using Ctrl+Click and then delete all the selected rows with a button?
View 1 Replies
Dec 9, 2010
I created a gridview with a checkbox in front of some columns. I need to grab the data the user is delecting and building an xml file.
Here is my code so far.
[code]....
View 2 Replies
Jun 20, 2012
SourceForm.aspx contains a databound gridview which I have added a checkbox column for multiple row selection. OnClick of a button I want to display any selected rows on another page, Target.aspxSo far I have successfully captured textbox input properites using PostBackUrl between the two, e.g.
SourcePage.aspx <div>
Enter your name: <asp:TextBox ID="_nameTextBox" runat="server" /><br />
Enter your age: <asp:TextBox ID="_ageTextBox" runat="server" /><br />
<asp:CheckBox ID="_marriedCheckBox" runat="server" Text="Married?" /><br />
<asp:Button ID="_nextPageButton"
[Code].....
Some examples I've tried to follow point towards using DataKey Rows of chkSelected
View 1 Replies
Oct 29, 2010
I have a list box that allows for multiple selections (holding down the control key) the selection quantity is basically unlimited, but realistically should never be more than 50 to 100 items from the listing of about 3000 items.
I could really use some building the SQL statement to select the choosen record data. I think I have the selection list worked out by populating an array but I am not clear on how to build the SQL query.
View 11 Replies
Nov 6, 2010
i'm using the code below to select multiple rows in a gridview using a checkbox, how do I modify the code in a "select all" button click event to select all the rows by checking the checkboxes in all the rows? How do I also clear all the checkboxes using sa "Clear" button click event?
[code]....
View 1 Replies
Nov 12, 2010
I have a GridView with an extra checkbox column to select rows.
To select multiple rows, the user now has to click each separate checkbox, but I would like to offer the possibility to select multiple rows at once using Shift+click.
Thus the user would explicitly select the first row with a single click and the select the last row using Shift+click. And the checkboxes of the rows in between would then automatically be checked as well.
View 3 Replies
Feb 10, 2010
i want to select rows between 15 to 30 from sql server so i am writing this:
SELECT uid, nname, nemail, ntelephone, naddress, ndate, uname, upassword, usertype, umonth, nregistration, regdate, paydetail, servicetype, serviceperiod,
View 3 Replies
Aug 9, 2010
I want to build a select query on the below resultset
[Code]....
[Code]....
The query will select the first n rows whose quantity is equals to the sum of my provided value i.e. 10
Now in the case of providing the value 10 the first 3 rows will select as the sum of 5,4, and 1 is equals to 10.
View 1 Replies
Mar 1, 2011
How to do this? I want to select rows where the datetime column is today's date.
SELECT * FROM table WHERE date = ??
View 5 Replies
Jan 23, 2011
Actually I have a gridview with many rows and I want to insert the all rows in sql server through one store procedure first row can inserted but what should we do for other rows
View 3 Replies
Jan 10, 2011
How can I combine multiple rows into a comma-delimited list in sql server in build function?? in HCL
examples :
X
---
12
15
18
20
Output : 12, 15, 18, 20
with in build function of sql server.
View 6 Replies
Jul 14, 2010
I have an asp.net 2.0 web app and one of the pages uses a grid to add/edit items before exporting the contents to excel. The items in the grid are selected based on a dropdown list--after the item in the list is selected, the grid goes and gets the items, populates a dataset and binds the dataset to the gridview. Some of my users are experiencing an issue where after deleting a random number of rows, a row not deleted will disappear or reappear. Though I have witnessed the behavior, I cannot duplicate it on my machine where the developement occurs (Win XP Pro, IIS 5.1, vwd2005 express). The windows 2003 server uses ASP.Net 3.5
Here is the code related to editing and deleting:
[Code]....
If I had to make a guess as to what was occuring, I would say that it appears at times to retain the deleted item's index after the grid is sent back to the user and tries to delete another row. But like I said, I can't duplicate the problem on my dev machine. if this might be caused by .Net 3.5 trying to run a 2.0 site?
View 5 Replies
Jul 27, 2010
i want to select rows between 15 to 30 from sql server so i am writing this:SELECT uid, nname, nemail, ntelephone, naddress, ndate, uname, upassword, usertype, umonth, nregistration, regdate, paydetail, servicetype, serviceperiod,
View 4 Replies
Jan 14, 2010
How can I select a random row and then update or delete it? I've found how to get a random row, using SELECT TOP 1 column FROM table ORDER BY NEWID() do I have to make another select using this result in order to update the row, or it can be done more efficiently?
View 10 Replies
Jul 24, 2010
I am accessing rows in an SQL database table based upon the contents of the Primary key and another column. But, I cannot insert new rows in the table when the content of the new Primary key column already exists in another row. Can I define the table with a multiple column Primary key so that a unique value can be based upon the content of both columns?
View 3 Replies
Feb 21, 2011
I have a website where users are going to enter recurring meetings/events. What's the most efficient way to insert this data? For instance, let's say a user wants to store a meeting for every monday at 8am. This would be a weekly meeting and I would run a loop and add 7 days to each meeting and then insert each row into SQL. Is it efficient to just run the insert command (cmdinsert.executenonquery()) for every week?
View 4 Replies
Apr 2, 2010
I have two tables, events and photos, in the relationship one event to many photos, joined by Event_ID.
I want to write an SQL Query, to display one random photo from each event in the database.
What would I have to write to make it do this? I know its something to do with Inner Join and Group by, but I'm not sure.
Field Names:
Photos.PhotoID
Photos.Event_ID
Events.Event_ID
Events.Event_Title
View 25 Replies