Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 5972933
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T20:43:41+00:00 2026-05-22T20:43:41+00:00

Hi I’m working on a strange project that has led me to some strange

  • 0

Hi I’m working on a strange project that has led me to some strange places and here I am again. Essentially there is a search of oh about 100 some odd controls (criteria which can each have nested multiple or’s) (Multi Select ListBoxes) … I don’t like using Dynamic SQL but due to the nature of the app I found it necessary I wrote a rather short C# back end (this is in ASP) that checks which controls are selected, takes the name value for the control (which is the column name) and builds a dynamic where clause … Example …

SELECT TOP 50000 [lname] as 'last',[fname] as 'first',[phone],[wphone],[fax],[cellphone],[email],[state],[zip],[state_w],[zip_w],[employer],CONVERT(char, [datebirth], 101) FROM [RT2DBSQL_Review].[dbo].[Respondent] WHERE (education = '5' ) and (race = 'H' ) and (hours = '1' ) and (',' + CC5 like '%,2,%' or ',' + CC5 like '%,26,%' or ',' + CC5 like '%,12,%') and (',' + CC6 like '%,9,%' or ',' + CC6 like '%,23,%') and (',' + CC4 like '%,Nintendo DS,%') and (gender = 'M') AND Pro_resp is null

This is checked and binds a grid to show the matching person(s).

The next step is. Say there are 1000 viable applicants choose x number of random applicants and insert dynamic values from respondent table (see below), static jobnum, static quota, all while feeding in the crazy ass where clause. I have all the individual pieces of this but am getting jammed up on getting it to work together.

Something Like:

CREATE PROCEDURE TEMPTEMP
@jobnum varchar(100),
@quota varchar(100),
@X int,
@Dynamic varchar(max)
AS
INSERT INTO [RT2DBSQL_Review].[dbo].[tbl_job_respondents]
([job_resp_job_number]
,[job_resp_respondent]
,[job_resp_name]
,[job_resp_phone]
,[job_resp_wphone]
,[job_resp_wphone_ext]
,[job_resp_cellphone]
,[job_resp_call_status]
,[job_resp_scheduled]
,[job_resp_recruited_by]
,[job_resp_part_status]
,[job_resp_coop_amt]
,[job_resp_amt_paid]
,[job_resp_status]
,[job_resp_part_check_no]
,[job_resp_session]
,[job_resp_date_pulled]
,[job_resp_date_recruited]
,[job_resp_quota]
,[job_resp_source]
,[job_resp_confirmed]
,[job_resp_referred_by]
,[query_print_field]
,[job_resp_exported]
,[job_resp_notes]
,[job_resp_childname])
VALUES
(@jobnum
,(Select TOP (@X) RecordId
,lname + ', ' + fname
,phone
,wphone
,wphone_ext
,cellPhone
,'0' --static
,0 --static
,'' --static
,'' --static
,0 --static
,0 --static
,'0' --static
,null--static
,null--static
,GETDATE()
,GETDATE()
,@quota
,'Q' --static
,null--static
,null--static
,0 --static
,0 --static
,null
,null/*static*/FROM Respondent
WHERE @Dynamic
ORDER BY NEWID()))
GO

The alternative is to load everything on the select into an array list whatever ?? Any Ideas I’m having a brain fart with this.

Thanks in advance for the help

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-22T20:43:42+00:00Added an answer on May 22, 2026 at 8:43 pm

    First of all I am going to strongly recommend that you view SQL as any other code and add consistent formatting to it.

    That said, the following trick should pick 1000 random records out of your 50,000 first records that you already had.

    SELECT TOP(1000) *
    FROM (
        SELECT TOP 50000 [lname] as 'last'
          , [fname] as 'first'
          , [phone]
          , [wphone]
          , [fax]
          , [cellphone]
          , [email]
          , [state]
          , [zip]
          , [state_w]
          , [zip_w]
          , [employer]
          , CONVERT(char, [datebirth], 101)
          , RAND() as priority
        FROM [RT2DBSQL_Review].[dbo].[Respondent]
        WHERE (education = '5' )
          AND (race = 'H' )
          AND (hours = '1' )
          AND (',' + CC5 like '%,2,%' or ',' + CC5 like '%,26,%' or ',' + CC5 like '%,12,%')
          AND (',' + CC6 like '%,9,%' or ',' + CC6 like '%,23,%')
          AND (',' + CC4 like '%,Nintendo DS,%') and (gender = 'M')
          AND Pro_resp is null
      ) full_sample
    ORDER BY priority
    

    Based on that creating your insert should not be too bad. (It will be a mess, but that’s life sometimes. More importantly it is a repetitive mess, and repetitive means that you can template it.)

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I've got a string that has curly quotes in it. I'd like to replace
I know there's a lot of other questions out there that deal with this
I'm working with an upstream system that sometimes sends me text destined for HTML/XML
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have just tried to save a simple *.rtf file with some websites and
I want to count how many characters a certain string has in PHP, but
For some reason, after submitting a string like this Jack’s Spindle from a text
I have a small JavaScript validation script that validates inputs based on Regex. I

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.