Criteria Search Query

Jul 30, 2007

I have four criterias in my .aspx page. They are "First Name, Last Name, Title, Year". I have a Book and an Author table. The Author table would contain all the author's information and the Book table contains all the books information such as title, publisher, subject, and so on. So here's what I'm trying to do.

I want to write a transaction statement that will query the four criterias above if the criteria textbox is not black. So for example, when the user click the submit button, all the four criteria fields are filled except Year. That means the query would search the Author and Book tables for "First Name, Last Name, Title" but not "Year" for any potential matches. I also wanted to use "Like" instead of "=" for a wider search.


Actually I'm trying to create a store procedure that will accept those four criterias and search the tables based on those criterias.

Any help is appreciated.

View 11 Replies


ADVERTISEMENT

Command With Several Search Criteria

Dec 4, 2013

I am very new to sql programming. I have a database with 15 columns. At this moment I do this to get all rows containing the year 2013:

WHERE DATEPART (yyyy, DownloadDate) = 2013 .

But I also want to add a criteria so that I can have all rows where DownloadDate contains 2013 AND WHERE IsRead(BIT) contains NULL. I tried this:

WHERE DATEPART(yyyy, DownloadDate) = 2013 AND IsRead = null .

But this gave me nothing!

View 3 Replies View Related

How To Put Single Quatation ' In Search Criteria

Feb 3, 2007

i am working for a Library Project. in that project i want to search Book by putting book content. in book content there could be single quatation
e.g William's. when ever i put single quatation my string type is terminated and my query is not executed successfully.
select Book_ID,Title,Auther from book_details where Contents like '%xyz%'
here xyz is my object name.
if i put William's in xyz it does not work.
plz tell me how to solve this problem.
Jasim...
New Delhi, INDIA

View 4 Replies View Related

Variable In Search Criteria(URGENT)

May 31, 1999

dear friend,
the problem i am finding is moreover a concatenation problem
what i did is that have stored procedure which is accepting any character and i have to show all the records where this character is existing
it is like this only
********************************
name1 like '% @str %'
but then it is not treating the str as a variable and treating it as a string so if you have any solution please let me know early
please give the answer with example
waiting for reply
ashish bhatnagar

View 1 Replies View Related

Handling Multiple Search Criteria

Mar 20, 2012

I am working on SQL Server in VB 2008. I have a table 'Records' having 8 columns. I have a search page where I can choose 5 different parameters to search as 'Category' , 'Name' , 'Date' etc.

I can successfully search with a single criteria selected either Category Name Or Date. But I want to create a single SQL command that can search my 'Records' table for either two or all the parameters depending on the selections made by the user.

View 5 Replies View Related

Criteria; Search Any Word In Field

May 26, 2004

I am trying to set up a query that will allow the user to input a string, and the search will match ANY word in that string. Currently, I have it configured so that the search will only match the exact string that the user inputs. I have google searched for the answer, but no luck yet. Any ideas?

View 9 Replies View Related

SQL 2012 :: Search Criteria Parameter Value

Jun 20, 2014

Say I have a query like

DECLARE @ID UNIQUEIDENTIFIER, @SOMEDATE DATE
SELECT * FROM myTable WHERE ID = @ID AND DATEFIELD=@SOMEDATE
I want to pass values to @ID and @SOMEDATE, such that it meets the WHERE criteria for all values in the respective fields.

What parameter value should I pass such that all values are selected? In the actual SP, I have uniqueidentifier, varchar and date parameters.

View 2 Replies View Related

Output Search Criteria For Multiple OR?

Oct 21, 2014

My selection criteria is as follows:

where content like '%EditLiveJava%'
or content like '% Sys__%' ESCAPE '_'
or content like '%<div class="row"/>%'
or content like '%<a href="" title=""%'
or content like '%cmsprod%'
or content like '%Error processing inline link%'
or content like '%see log for stack trace%'

I output the content field if the search is true but would like to also output which specific 'like' has been found.

Can I do this in the one pass or do I have to read the database separately for each condition?

View 3 Replies View Related

Stored Procedure - Search By Two Or Any One Of Criteria

Apr 7, 2015

I have a store procedure that search by Firstname and Lastname. I want it search by either both (Firstname and Lastname) or any of them. For example if only FirstName passes to it shows all the record with that Fistname. Currently I have to pass both Firstname and Lastname to my store proc to get the result.

This is my stor proc:

USE [CustomerPortal]
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
ALTER PROCEDURE [dbo].[CSA_Search_Customer_By_Name]

[Code] ....

View 4 Replies View Related

How Do I Search For The Same Criteria In Three Or More Fields In One Table?

Jul 23, 2005

I am trying to create a query that will show me who is phoning who in anorganisation from available Telephone Billing information. I am creating aMSAccess 2000 database with a few few tables, two of which are:TableMembers: (containg fields Refs, DateCreated, MembershipNo,OfficeLocation ...NB: Refs has a Primary Key - No Duplicates)TablePeople: (containing fields: Refs, Name, Addr, TelHome, TelWork,TelMobile & TelFax)TableTelBills: (containing fields: Refs, TelNo, DateCalled, Duration,TelType)I am trying to create a query that will use a simple searching criteria eg.,Like "*" [Enter the Tel No or part Tel No to search:] & "*"to search all the Tel fields in the TablePeople and TableTelBills (TelHome,TelWork, TelMobile, TelFax and TelNo) but am running in difficulties.I start by creating a query and adding the tables TablePeople andTableTelBills and TableMembers.I use the Refs from the Table Members as a base criteria but do not know howto create criteria that will search all Tel fields at once!I would appreciate any and all help people!Jan

View 2 Replies View Related

NO Records In Result Set When Non-alphanumerics Are Used In Search Criteria

Nov 5, 1999

I'm trying to figure out why I am not getting any result set back from a search that includes non-alphanumeric
or non-printable characters. For instance, if I have a table with a 20 character name column with names with
beginning ranges from A-Z, why doesn't the following return any rows:
select * from table where name < CHAR(126).
In the ASCII character set, 126 is a tilde (~) which is numerically above the alphanumeric ranges 1-9,a-z, and
A-Z. Shouldn't all records that sort lower in the character range be included in the result set ?

I'm assuming this has something to do with the default collation sequence being used which somehow does
not include characters outside the alphanumeric range. Any ideas ?

View 4 Replies View Related

SQL Server 2008 :: How To Hide Criteria In Search Results

May 28, 2015

Say I want to search for a range of account numbers but only which are active. After I set my field for A (active) this field shows in my results, I dont want it to.

In Access you can easily just uncheck that field in design view, but how do I do it in sql?

View 4 Replies View Related

Simple Function For Returning A Character Based On Search Criteria..

Feb 20, 2007

Hi,how do I do a simple formula, which will search a field for specialcharacters and return a value.If it finds "%" - it returns 1elseIf it finds "?" it returns 2endIf this is the incorrect newsgroups, please direct me to the correct oneregards Jorgen

View 2 Replies View Related

Transact SQL :: Use Query Results As Select Criteria For Another Query

Jul 10, 2015

I have a query that performs a comparison between 2 different databases and returns the results of the comparison. It returns 2 columns. The 1st column is the value of the object being compared, and the 2nd column is a number representing any discrepancies.What I would like to do is use the results from this 1st query in the where clause of another separate query so that this 2nd query will only run for any primary values from the 1st query where a secondary value in the 1st query is not equal to zero.I was thinking of using an "IN" function in the 2nd query to pull data from the 1st column in the 1st query where the 2nd column in the 1st query != 0, but I'm having trouble ironing out the correct syntax, and conceptualizing this optimally.

While I would prefer to only return values from the 1st query where the comparison value != 0 in order to have a concise list to work with, I am having difficulty in that the comparison value is a mathematical calculation of 2 different tables in 2 different databases, and so far I've been forced to include it in the select criteria because the where clause does not accept it.Also, I am not a DBA by trade. I am a system administrator writing SQL code for reporting data from an application I support.

View 6 Replies View Related

Help W/ Stored Procedure? - Full-text Search: Search Query Of Normalized Data

Mar 29, 2008

 Hi -  I'm short of SQL experience and hacking my way through creating a simple search feature for a personal project. I would be very grateful if anyone could help me out with writing a stored procedure. Problem: I have two tables with three columns indexed for full-text search. So far I have been able to successfully execute the following query returning matching row ids:  dbo.Search_Articles        @searchText varchar(150)        AS    SELECT ArticleID     FROM articles    WHERE CONTAINS(Description, @searchText) OR CONTAINS(Title, @searchText)    UNION    SELECT ArticleID     FROM article_pages    WHERE CONTAINS(Text, @searchText);        RETURN This returns the ArticleID for any articles or article_pages records where there is a text match. I ultimately need the stored procedure to return all columns from the articles table for matches and not just the StoryID. Seems like maybe I should try using some kind of JOIN on the result of the UNION above and the articles table? But I have so far been unable to figure out how to do this as I can't seem to declare a name for the result table of the UNION above. Perhaps there is another more eloquent solution? Thanks! Peter 

View 3 Replies View Related

Query Criteria Format

Feb 9, 2004

I have a text box that is used to submit stock symbols that are to be saved in a sql table. The symbols are to be separated by a space or a comma (I don't know which, yet). I want to retrieve the symbols later to be used in a query, but I don't know how to get the symbols in the proper string format for the query, eg

The symbols are stored in the tables as: A B C D
The query string criteria would look like: IN('A', 'B', 'C', 'D')

The IN('A', 'B', 'C', 'D') citeria would be the values in the @Symbol variable in this SPROC

SELECT a_Name_Symbol.Symbol, a_Financials.Revenue
FROM a_Financials INNER JOIN
a_Name_Symbol ON a_Financials.Symbol = a_Name_Symbol.Symbol
WHERE (a_Name_Symbol.Symbol @Symbol)
ORDER BY a_Name_Symbol.Symbol

Is there a slick (ie easy) way to change the contents entered in the text box (A B C D) into IN('A', 'B', 'C', 'D') ?

Thanks,

Paul

View 1 Replies View Related

Using Results From One Query As Criteria For Next

Jan 4, 2006

I have a database with some over normalized tables in it.  The best I can do with one query is get the file ID.  In the second query I want to get all the file names, based on all the fileID's I got from the first query.  How would I go about doing this?

View 5 Replies View Related

Slow Query Due To Criteria

Jan 24, 2008

I have a query in access that is running extremely slow and I'm trying to find a better way to write it. It appears to be the criteria statement that is causing the lag. Is there a better way to write this? And unfortunately I have to keep it in access.

query:
SELECT DISTINCT "JBC" AS ClientCode, PaymentDetail.PatientNumber, Procedures.CaseNumber, IIf(IsNull([TicketNumber]),Procedures.patientnumber & Year(Procedures.dateofservice) & Month(Procedures.dateofservice) & Day(Procedures.dateofservice),Procedures.ticketnumber) AS ClaimNumber, PaymentDetail.PaymentCounter, PaymentDetail.TransAmount, Payments.PaymentDate, PaymentDetail.AccountingDate, PaymentDetail.TransDate, payments.PaymentType & "-" & Adjustments.adjustmentcode AS CombinedPmtType, Payments.PaymentType, Payments.PaymentCode, Adjustments.AdjustmentCode, PaymentCodes.BriefDescription, PaymentCodes.LongDescription, Payments.CarrierCode, Payments.Remarks, Procedures.ProcedureCode, Procedures.DateOfService, PaymentDetail.DetailCounter
FROM ((((PaymentDetail LEFT JOIN Procedures ON (PaymentDetail.PaymentCounter = Procedures.Counter) AND (PaymentDetail.AccountingDate = Procedures.AccountingDate) AND (PaymentDetail.PatientNumber = Procedures.PatientNumber)) LEFT JOIN Payments ON (PaymentDetail.TransDate = Payments.AccountingDate) AND (PaymentDetail.TransCounter = Payments.Counter) AND (PaymentDetail.PatientNumber = Payments.PatientNumber)) LEFT JOIN PaymentCodes ON Payments.PaymentCode = PaymentCodes.PaymentCode) LEFT JOIN Adjustments ON (PaymentDetail.TransDate = Adjustments.AccountingDate) AND (PaymentDetail.PatientNumber = Adjustments.PatientNumber)) LEFT JOIN AdjustmentCodes ON Adjustments.AdjustmentCode = AdjustmentCodes.AdjustmentCode
WHERE (((Procedures.CaseNumber)=0) AND ((PaymentDetail.TransAmount)<>0) AND ((Payments.PaymentType) Is Null) AND ((PaymentDetail.DetailCounter)=2)) OR (((Procedures.CaseNumber)=0) AND ((PaymentDetail.TransAmount)<>0) AND ((Payments.PaymentType) Is Null) AND ((PaymentDetail.DetailCounter)=5) AND ((AdjustmentCodes.InsuranceIndicator)="N"));

View 5 Replies View Related

Best Practice Question: JOIN Criteria Vs. WHERE Criteria

May 24, 2004

For example, consider the following queries:


DECLARE @SomeParam INT
SET @SomeParam = 44

SELECT *
FROM TableA A
JOIN TableB B ON A.PrimaryKeyID = B.ForeignKeyID
WHERE B.SomeParamColumn = @SomeParam

SELECT *
FROM TableA A
JOIN TableB B ON A.PrimaryKeyID = B.ForeignKeyID AND B.SomeParamColumn = @SomeParam


Both of these queries return the same result set, but the first query filters the results in the WHERE clause whereas the the second query filters the results in the JOIN criteria. Once upon a time a DBA told me that I should always use the syntax of the first query (WHERE clause). Is there any truth to this, and if so, why?

Thanks.

View 3 Replies View Related

Query On Unique Records With Multiple Criteria

Oct 19, 2013

I'm fairly new in SQL. Been trying for months to create the right script for this particular case but still cannot give me 100% result as required.

SCENARIO :

I am required to query from 2 tables for those unique record that meets both conditions below:-
1. Status is 1 @ max (trans_id), paychnl = CC
2. Status is 2 @ max (trans_id), paychnl = A or B

FYR, 2 tables and respective columns to query are as below:-
table PTFF --> col ID, TRANS_ID,TRANSDATE,EFFDATE,TRANSCODE
table CHFF --> col STATUS,PAYCHNL

FYI, status refers to the paychnl method status:-
==> 1 means the current paychnl method
==> 2 means the previous paychnl method

paychnl method can be multiple because it will be defined as 2 for all the histories' paychnl chosen earlier, but 1 should only be unique as it is the latest paychnl chosen for each unique ID. however, it may appear more than once when it's taking those in earlier TRANSDATE, so here we would need the max trans_id as it will show the latest updated TRANSDATE.

Apart from that, I need only those most recent paychnl to be A or B and the latest paychnl is CC so, this been indicated by the same max trans_id for the same ID.

Aft trying so many times on this MAX command but failed to get any result, I only managed to come up to this part only. please refer below:-

table PTFF --> col ID, TRANS_ID,TRANSDATE,EFFDATE,TRANSCODE
table CHFF --> col STATUS,PAYCHNL

SELECT DISTINCT PTFF.TRANSCODE,PTFF.ID,PTFF.TRANS_ID,PTFF.TRANSDATE,PTFF.EFFDATE, CHFF.STATUS,CHFF.PAYCHNL

FROM DBO.PTFF PTFF
JOIN DBO.CHFF CHFF
ON CHFF.ID = PTFF.ID
WHERE
PTFF.TRANSDATE BETWEEN 130501 AND 130831
AND PTFF.TRANSCODE='T522'
AND (CHFF.STATUS=1 AND CHFF.PAYCHNL='CC' OR (CHFF.STATUS=2 AND (CHFF.PAYCHNL='A' OR CHFF.PAYCHNL='B')))

However, the script above returns :-

1. All those records with STATUS 1 regardless paychnl is A or B in most recent status 2,
2. Expected results also appear ==> 1 same ID with status 1 while paychnl=CC and status 2 while paychnl=A or B
3. Also duplicates of expected results but for different TRANSDATE and not at MAX TRANS_ID

Samples of the result:-

IDSTATUSTRANS_IDPAYCHNLTRANSDATEEFFDATETRANSCODE
51881712CC13082920130920T522
9361164CC13081620140813T522
78531153CC13082020130814T522
8949151CC13081220130801T522
8949251B13081220130801T522
19081455CC13051620131129T522
19082455A13051620131129T522
19081409CC11101920111129T522
19082409A11101920111129T522
19081404CC11092920111129T522
19082404B11092920111129T522

View 7 Replies View Related

Access Query Against SQL Server Works Only Without Criteria

Jun 23, 2006

Getting a weird error while trying out a query from Access 2003 on aSQL Server 2005 table.Want to compute the amount of leave taken by an emp during the year.Since an emp might be off for half a day (forenoon or afternoon), havethe following computed field:SessionOff: ([ForenoonFlag] And [AfternoonFlag])The query works fine when there's no criterion on SessionOff.However, when I try to get the records where the SessionOff equals 0, Iget the following error:~~~~~ODBC--call failed. [Microsoft][SQL Native Client][SQL server]Incorrect syntax near the keyword 'NOT'. (#156)~~~~~I checked the SQL of the Access query, but there's no NOT anywhere init:~~~~~SELECT tblWorkDateAttendance.*FROM tblWorkDate INNER JOIN tblWorkDateAttendance ONtblWorkDate.WorkDate = tblWorkDateAttendance.WorkDateWHERE (((([ForenoonFlag] And [AfternoonFlag]))=0) AND((tblWorkDateAttendance.WorkDate)<Date()) AND((Year([tblWorkDate].[WorkDate]))=Year(Date())) AND((Weekday([tblWorkDate].[WorkDate])) Between 2 And 6) AND((tblWorkDate.HolidayFlag)=False));~~~~~What gives?

View 4 Replies View Related

SQL 2012 :: Limiting Query Results With 3 Criteria For Each Record

Mar 20, 2015

I am trying to write a query that gives me the personal records from speed skaters on e.g. the 500 mtrs. I do this with the query:

SELECT cdsDistance AS Distance
, prsFirstName
, prsLastName
, min(crtFinalTime) AS MinTime
FROM tb....... INNER JOIN etc..
GROUP BY cdsDistance, prsFirstName, prsLastName
ORDER BY min(crtFinalTime)

In itself this works fine. However, there are complicating factors. Sometimes a speed skater has multiple PRs, meaning the he/she has the same fastest time more than once.

If these times are achieved on multple days, the 1st date is the official PR. (meaning: "Min of racedate")
If they are raced on the same day the 1st race is the PR (meaning: "Min of distancenumber")

Changing the code to:

SELECT cdsDistance AS Distance
, prsFirstName
, prsLastName
, MIN(crtFinalTime) AS MinTime
, MIN(cdsStartDate) AS RaceDate
, MIN(cdsDistanceNumber) AS DistanceNumber

FROM tb.......
GROUP BY cdsDistance, prsFirstName, prsLastName
ORDER BY min(crtFinalTime)

This gives me the wrong outcome because it gives me the "MIN" of every field, and they are not necessarily on the same row.

An option would be to calculate min(crtFinalTime), if for a person there is more than 1 result, calculate min of date, and then (if there is still more than 1 row) min of distancenumber.

Seems complicated, and I have the feeling there must be a better way (apart from: how to get this code)

Stacking subqueries in the FROM statement seems like a option be costly (time wise). There are more than 10 million rows (and growing) to run through.

As an example a few times:

DistanceFirst nameLast name Time Date Distance nr.
500 Yuya Oikawa 34.49 201311155
500 Yuya Oikawa 34.49 201311153
500 Yuya Oikawa 34.49 201311172

Yuya has 3 best times (34.49), 15-11-2013 is the 1st date, then distance nr 3 is the 1st distance raced. Therefore the 2nd row is the only row I would like to get in my endresult.

View 4 Replies View Related

SQL Select Query Need For Following Criteria. Please Help, Retrieve Records With Independent Price And Its Total Volume Per Min

Jul 17, 2006

Time       Price   Volume
090048       510      6749
090122       510      2101
090135       510      1000
090204       505      2840
090213       505      220
090222       505      1260
090232       505      850
090242       505      200
090253       510      1200
090313       510      570
090343       510      250
090353       510      160
 
Criteria
Retrieve records with independent price and its total volume per minute
 
SELECT SUBSTRING(st,1,4) AS Ttime,d_price AS Price,SUM(l_cum) AS Volume FROM cmd4
WHERE sd='20060717' AND serial='0455'
GROUP BY SUBSTRING(st,1,4),d_price,l_cum
 
Result of the above query: -
Time  Price Volume                 
0900    510     6749
0901    510     1000
0901    510     2101
0902    505     200
0902    505     220
0902    505     850
0902    505    1260
0902    505    2840
0902    510    1200
0903    510    160
0903    510    250
0903    510    570
 
 
THE FOLLOWING RESULT STILL NOT A TOTAL FOR A MINUTE]
E.G
 
0901    510            1000
             +
0901    510            2101
            =         
0901    510            3101 <- I NEED THIS
 
Can any one advice or give me tips over this. Please
 

View 3 Replies View Related

Can’t Understand The Query Execution Interval, For Every One Criteria It Takes Extra 60 Seconds. Help Please?,

Aug 17, 2006

Can€™t understand the Query execution interval, for every one criteria it takes extra 60 seconds. Help please?,  







Query A

SELECT TOP 15 * FROM CMD4 AS T1 WHERE T1.ST IN

(SELECT max(T2.ST) FROM CMD4 AS T2 WHERE T1.SERIAL=T2.SERIAL

AND T2.sd='20060817') AND sd='20060817'

--AND STOCKNAME like 'A%'

ORDER BY D_CUM desc;

The above query take 2 seconds to return result







Query B

SELECT TOP 15 * FROM CMD4 AS T1 WHERE T1.ST IN

(SELECT max(T2.ST) FROM CMD4 AS T2 WHERE T1.SERIAL=T2.SERIAL

AND T2.sd='20060817') AND sd='20060817' AND STOCKNAME like 'A%' ORDER BY D_CUM desc

This query same as above but " AND STOCKNAME like 'A%'" Criteria only added but it takes 01 minute 43 seconds to return result. why it is like that where i need to adjust the query i have no idea. please help

View 1 Replies View Related

SQL 2000 MS Search: Boolean Search Doesn't Work When Search By Phrase

Aug 9, 2006

I'm just wonder if this is a bug in MS Search or am I doing something wrong.

I have a query below

declare @search_clause varchar(255)

set @Search_Clause = ' "hepatitis b" and "hepatocellular carcinoma"'

select * from results

where contains(finding,@search_clause)

I don't get the correct result at all.

If I change my search_clause to "hepatitis" and "hepatocellular carcinoma -- without the "b"

then i get the correct result.

It seems MS Search doesn't like the phrase contain one letter or some sort or is it a know bug?

Anyone know?

Thanks

View 3 Replies View Related

SQL Search Query Help!

Sep 11, 2004

I am having hard time figuring out what query I need to write.


What I want to do is, when users enter a word into a textbox, it displays results similar to it. Something similar to what Google does.

This is what I am doing now.
For example I will use "John Smith"

1. I get the first 3 letters of the string "Joh"
2. Get the last letter of the string "h"
3. and this is what I search for "Joh%h%"

This works, but I still have some problems. I want to be able to search like Google, where it recognizes words. Does anybody know how I can do this, or send me a link with an example?

Thank you

View 3 Replies View Related

About Search Query

Aug 2, 2005

I would like to write query which can1.  ignore whether the search keyword is Upper case or lower Case2. deal with tense or verb form related  problem    eg. comparing --> also search compareAny Idea

View 9 Replies View Related

Search Query

Aug 16, 2005

hi all
I have the follwoing search page:
several text boxes in case they want to search for SSN, first name,
last name, zipcode, several dorpdown lists, and a set of radio buttons.
I want to create the SQL statement to display the results
I am checking if any of the text boxes has anything in it, if yes add
"where something = value" to the query, if not then skip... now let's
say it goes through textbox 1 and finds it empty, so it jumps to the
second one it find info in it, how do I deal with the "and" clause
within the query?
any tips are fine.. (im using c#)
thanks

View 7 Replies View Related

Need Query Help For Search

Feb 28, 2006

I am writing a small search feature to return a list of companies whose name "Begins with" a certain string (up to 5 chars) provided by the user via a textbox.  I want the results to only return results that begin with the letter/letters specified.  Below I will put the code that I came up with that isn't working quite how I expected.  I am new to this so any assistance and short explanation would be very much apperciated.
sql="SELECT distinct cm.cmmst_id, cm.cm_compno, cm.cm_cname1 + ' ' + cm.cm_cname2 AS cm_cname1, cm_tele, cm_fax, cm_s16 "
sql=sql & "FROM cmmst cm "
sql=sql & "WHERE cm_cname1 + ' ' + cm_cname2 LIKE '%" companyNameBegins,"'","''") & "%' " sql=sql & "AND (cm_mbtyp='M' OR cm_mbtyp='SUBDIV') " sql=sql & "ORDER BY cm_s16 DESC, cm_cname1 ASC"
companyNameBegins is the string passed in by the user
 
Thanks,
Zoop

View 2 Replies View Related

SQL Search Query

Mar 27, 2001

Hello-

I am having a difficult time figuring out the differences between the following 2 queries. The first query ( which should return around 8000 records) when run against a Sql7 DB with 70000 records will always timeout (timeout set at 30 secs), but the 2nd query will return the correct amount of records ( about 8000 ) in under 8 secs.

Could someone shed some light on this for me?

Thank you
Robert

******Start Query 1******
Select Lot, Title, UserId, HighBidder, HighBid,
BidTimes, DateIn, EndDate, Price, Category, Options,
Reserve, StartDate From Auctions A Where (
((title LIKE '%STUB%' )) or ((description LIKE '%STUB%' ))
) And (Status In ('A', 'P') Or (Status In ('B', 'C')
And EndDate >= '02/25/2001')
) And ((A.Reserve > A.Price And A.Reserve Between 0
And 999999.99)
Or (A.Price Between 0 And 999999.99))
Order By Lot Asc




*****End Query 1*****

******Start Query 2******
Select Lot, Title, UserId, HighBidder, HighBid,
BidTimes, DateIn, EndDate, Price, Category, Options,
Reserve, StartDate From
(Select Lot, Title, UserId, HighBidder, HighBid,
BidTimes, DateIn, EndDate, Price, Category, Options,
Reserve, StartDate,Description From Auctions A Where
(A.Status In ('A', 'P')

Or (A.Status In ('B', 'C') And
A.EndDate >= '02/25/2001')

) And ((A.Reserve > A.Price And A.Reserve Between 0
And 999999.99)
Or (A.Price Between 0 And 999999.99))
) as X
Where (

( (title LIKE '%STUB%' ))


or ( (description LIKE '%STUB%' ))



)
Order By Lot Asc

******End Query 2******

View 1 Replies View Related

Need Help On Search Query.

Sep 6, 2007



Hello All!

I'm building a serch page on website. It basicly searches 2 tables. Right now, the way I have it so the user can enter a value in one of the fields, and not the others. And it will return the value. For example, put in '34' in the age field, it will return all people with 34. Now if you add 'Jones' to the last name field, it will return all people with the age of 34, and all people with Jones.

But what if I want it so it returns only the people with the age 34, and Jones. But leave the other fields blank. The later than add 'Jim' to the first name, so now it will return 34, jones, jim. I tried to use the AND operator, but then it requires that field to be filled. Here is my code.

ALTER PROCEDURE [dbo].[SrchActiveII]

@FName nvarchar(50)=NULL,
@LName nvarchar(50)=NULL,
@DOB nvarchar(50)=NULL,
@Acct nvarchar(50)=NULL,
@Login nvarchar(50)=NULL,
@Status nvarchar(50)=NULL,
@Rmark nvarchar(255)=NULL,
@Room nvarchar(50)=NULL,
@Age nvarchar(50)=NULL,
@Type nvarchar(50)=NULL,
@Misc bit = NULL
AS
BEGIN
SELECT Active_Orders.First_Name, Active_Orders.Last_Name, Active_Orders.Account_Number, Order_Status.Status, Active_Orders.Remarks,
Locations.Loct_Desc, Active_Orders.Rm_Desc, Active_Orders.Age, Active_Orders.Type, Active_Orders.Stat,
Active_Orders.Order_ID, Active_Orders.Login, Active_Orders.Misc
FROM Active_Orders INNER JOIN
Order_Status ON Active_Orders.Status_ID = Order_Status.Status_ID INNER JOIN
Locations ON Active_Orders.Location_ID = Locations.Location_ID
WHERE (Active_Orders.First_Name =@FName) OR (First_Name IS NULL) OR
(Active_Orders.Last_Name =@Lname) OR (Last_Name IS NULL) OR
(Active_Orders.DOB = @DOB) OR (DOB IS NULL) OR
(Active_Orders.Account_Number = @Acct) OR (Account_Number IS NULL) OR
(Order_Status.Status = @Status) OR (Status IS NULL) OR
(Active_Orders.Remarks = @Rmark) OR (Remarks IS NULL) OR
(Active_Orders.Rm_Desc = @Room) OR (Rm_Desc IS NULL) OR
(Active_Orders.Age = @Age) OR (Age IS NULL) OR
(Active_Orders.Type = @Type) OR ([Type] IS NULL) OR
(Active_Orders.Login = @Login) OR ([Login] IS NULL) OR
(Active_Orders.Misc = @Misc) OR (Misc IS NULL)
END

Thanks!

Rudy

View 7 Replies View Related

Need Help In Search Query...

Apr 9, 2007

Hi,

I am making a search query for jobs site. I have a situation that if user type following string in my search box:



Web Developer Designer ISF New York



It should display all jobs conatins any one of given words. following are columns in my jobs table: (Query will be applied on Location, Title, Description, Company fields)








Jobs


JobID




PostedDate


Company


URL


Location


Title


Description


Contact







please help me what will be the query.

Thanks,

Bye.

View 7 Replies View Related

Simple Search Query

Mar 16, 2007

Hi,

 

I'm writing
small search engine for my page. I need SQL query that could do this:

 

Source:

 

tblColours

------------

Red

GreenRed

White Red

Yellow

Blue Green

Yellow RedF

 

Search
string: Red

 

Required
results:

 

Red

White Red

Yellow RedF

 

As you can
see I need all occurrences of word Red and word Red* but I don’t need *Red or
*Red* so I can't use LIKE %Red% :(.

 

P.S. Sorry
for my English.

Fizikas.

View 1 Replies View Related







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