SQL Server :: Random Select With Multiple Criteria?

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


Similar Messages:

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

SQL Server :: Search Criteria For Multiple Columns?

Nov 18, 2010

im trying to write a query. for my ui ,i have 3 text boxes for firstname,flightno,sequencenumber.

i input search value on particular textbox it has to be searched on particular column of my db in a single stored procedure.

im using this procedure but it retrives only one column at atime. so like this i need to write three procedures.

but i have only one GO button.

ALTER PROCEDURE [dbo].[spp_searchUsers3]
@lastname nvarchar(50),
@Value varchar(50)
AS
DECLARE @SQL nvarchar(500)
SET @SQL = 'SELECT firstname,flightnumber,lastname,status FROM tbl_pregister WHERE '
+ @lastname + ' LIKE ''%' + @Value + '%'''

View 4 Replies

SQL Server :: SELECT Random Records In Term Of Time

Sep 27, 2010

I want to return random records in term of time whithout NEWID

View 5 Replies

Web Forms :: If The User Doesnot Select Any Of The Above Three Then A Message Gets Displayed As "Please Select One Search Criteria?

Mar 2, 2011

Can any one let me know about the below issue. I have a page which has three labels, say startdate,enddate and username. My issue is if the user doesnot select any of the above three then a message gets displayed as "Please select one search criteria" or if the user doesnot enter the date in correct format then i dispaly "Please enter date in mm/dd/yy" format. But what is happening is first time if the user doesnot select any then "Please select one search criteria" is getting displayed and after this message gets displayed if the user enters wrong format of date then both the messages are displayed.

View 5 Replies

SQL Server :: Select Random 10 Records In 2005 In Terms Of Time

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

SQL Server :: Stored Procedure To Select Random Column Value From A Selected Row?

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

SQL Server :: How To Code To Populate Gridview With Multiple Random List Box Selections

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

SQL Server :: Finding Code To Populate Gridview With Multiple Random List Box Selections?

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

C# - LINQ To Entity Framwework Multiple Joins With Multiple Dynamic Search Criteria?

Jul 2, 2010

The gist of the problem is that we have an alumni table (one record per person) and also a couple of other tables (one to many) that have degree info and interest info. In a search screen in our app you can search for criteria that spans all three tables (there are actually more fields and tables than shown in the example below but I am trying to keep it simple).

The code below works (properly returns people without degrees for example) but still feels a little clunky or over-engineered to me. Are there easier ways to do this? NOTE: I have been through quite a few iterations/approaches to making the correct data be returned.

[code]....

View 1 Replies

C# - NHibernate Select Most Recent Record That Meets Criteria?

Jan 27, 2010

Last night I started working on an NHibernate provider. I'm creating a criteria that several records will match, however I only want to return the most recent record (the record with the largest Id). I thought UniqueResult() would do this it cannot be used if a list would be returned otherwise.

I could theoretically select the full list and then return the desired record, but I believe there is a better way.

View 2 Replies

DataSource Controls :: Optional Select Criteria For An SqlDataSource?

Oct 6, 2010

I have a form that searches for images in a database. I have several DropDownLists with various search criteria e.g. Genus, Photographer, State, Project.I'd like the user to be able to filter using any combination of these. For example they might pick a specific photographer and a specific genus but choose not filter by project or state.I'd like to find a good, clean, elegent way to do this.Here is an example of the code I have now, it has only two possible criteria. It works but I have a feeling there are better ways to do this....

[Code]....

View 3 Replies

DataSource Controls :: Searching Table With Multiple Criteria?

Apr 15, 2010

I want to select data from a table where the user can search by 3 options; date, keyword, and type. The date will always be either today or a user chosen date. The keyword can be null or something the user inputs. The type will be chosen from a drop down and can be all or a specific category. I know how to search the date, but the other two create complications. I have created a stored procedure trying to figure this out:

[Code]....

Is there a way to say if the keyword is null then don't use it as a search criteria. If that is possible then type can use that same logic I suppose.

View 6 Replies

Forms Data Controls :: Multiple Search Criteria ListView?

Jul 17, 2010

search form!Have no idea how to do it.Hope the example says much about how it should operate!Profile search where the result will come out in a list view.theusers should be able to filter between firstname, lastname, age, gender.right now I have this!Search page

[Code]....

Search result page

[Code]....

[Code]....

View 11 Replies

DataSource Controls :: MSSQL Select A Random Row?

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

DataSource Controls :: Select One Random Photo From Each Event?

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

SQL Server :: Multiple CTE With Different Select?

Aug 3, 2010

I have the syntax error below:

With Product ( ProductID, Qty) AS ( select productid, qty from xxxxx)
, With Order (OrderNo, Customer, Qty) AS (select xxxxx)
Select xxx

from Product inner join Order on ......

View 1 Replies

SQL Server :: Select Statement For Multiple Tables

Oct 1, 2010

SELECT u.Email FROM UserProfiles p, aspnet_Membership u WHERE p.RulesCheckBox = 'True' AND u.UserId = p.UserId This gives me a list of registered member email addresses that have selected the RulesCheckBox in their profile, so I can email them with an email script. There is a relationship between the Membership table and the UserProfile table, so it finds the email addresses from the Membership table where that user has the RulesCheckBox checked in their profile (in UserProfiles table). I'm wanting to add some additional names to this list, from a different table. The purpose is so I can manually add email addresses to the additional table, so the additional email addresses will also receive the same email, even though they aren't registered members of the site. So how can I adjust that SELECT statement so this one is combined with it somehow?:

SELECT Email FROM ExtraEmails WHERE Rules = 'true'

View 4 Replies

SQL Server :: Multiple Conditions In Select Command

Feb 27, 2011

Is it possible to have multiple conditions in an SQL select command. I have an SQL Table with the follwing filds.

Image1
Image1Approved
Image2
Image2Approved
Etc

Image1 is a varchar(50) and stroes the picture name. Image1Approved is a tinyint (0 = Pending, 1 = Declined & 2 = Approved) I am using the following to query the SQL database.

SelectCommand="SELECT Image1, Image1Approved, Image2, Image2Approved, Image3, Image3Approved FROM UserProfiles WHERE (UserId = @UserId)"

The part that I am stuck on is only returning the images that have there associated approved condition set. I know how to do this with a seperate select command for each image but can this be done for all image files in one statement.

View 5 Replies

SQL Server :: Assign Multiple Variables In A Single Select?

Feb 4, 2011

I am using MS SQL Server 2005 & here is my problem: I need to assign values to the multiple variables in a single select. But each value is depend on the certain value of the other column of the table.

declare @i1 Int, @i2 Int, @i3 Int;
select
case Table.column1
when 'red' then @i1 = Table.column2
when 'green' then @i2 = Table.column2
when 'blue' then @i3 = Table.column2
end
from
dbo.Table

how to achieve this in a single select?

View 3 Replies

Web Forms :: VB - Random Number For Multiple Labels?

Oct 9, 2010

Not sure if I'm approaching this correctly but this is what I've got and what I'm trying to do

I have a table with 10 Labels in it (Labels Id A1 thru A10)

I'm trying to have each label assigned a random number using 0-9

Need to have each labels number value different from the other

Code Below:

Randomize()
A1.Text = Int(Rnd() * 10)
A2.Text = Int(Rnd() * 10)
A3.Text = Int(Rnd() * 10)
A4.Text = Int(Rnd() * 10)
A5.Text = Int(Rnd() * 10)
A6.Text = Int(Rnd() * 10)
A7.Text = Int(Rnd() * 10)
A8.Text = Int(Rnd() * 10)
A9.Text = Int(Rnd() * 10)
A10.Text = Int(Rnd() * 10)

View 2 Replies

SQL Server :: Query To Select Data From Multiple Tables And A Different Database?

Dec 1, 2010

Is there a way to select data from multiple tables other than the UNION ALL statement. Addtionally I need to select data from a different database.

My current statement is as follows (there are alot more fields but I have shortened it ):

SELECT server.dbo.SRFILE.SR_GROUP, server.dbo.SRFILE.SROWNERSHIP, server.dbo.SRFILE.SRCONMAE, BSFLBWF_1.Incidentx,
BSFLBWF_1.Severityx FROM server.dbo.SRFILE INNER JOIN
BSFLBWF AS BSFLBWF_1 ON BSFLBWF_1.Incidentx = server.dbo.SRFILE.SRONUMBER
WHERE (BSFLBWF_1.Closex IS NULL).........

View 4 Replies

SQL Server :: Select - Multiple Dropdown Lists To Only Include Table1 Entries

Aug 1, 2010

I am trying to get the drop down list to only include table1 entries where table3.int1 is the current selection in another drop down list (table2.id). Example:

Table1: id, string1, int
Table2: id, string1, string2, dec
Table3: id, int1 (ref table2.id), int2 (ref table1.id)

Both drop down lists are inside of a FormView object for a asp.net page. My current select command(s) are having the DropDownList for Table1 display all Table3 entries, instead of just the ones Tied to Table2 id from the other DropDownList.

View 8 Replies

Web Forms :: Datareader: Set Multiple Random Images Into Appropriate Image Field

Sep 3, 2010

first of all, sorry if my title isn confusing as i dont really sure the specify description regarding what i wan to do. Now what i trying to do is, I getting 5 random images from the database, this is the code for me to get random 5 records from database:

[Code]....

I dont really know how to use array but willing to try if it is needed.

View 1 Replies

DataSource Controls :: Multiple Select Statements In Stored Procedure Sql Server 2005

Feb 4, 2010

Is it possible to add multiple select statements in a single stored procedure. The select statements are getting data from different tables. If yes, could anybody provide an example in adding multiple select statements, which retrieve data from different tables in a stored procedure.

View 3 Replies







Copyrights 2005-15 www.BigResource.com, All rights reserved