I have an application that connects to a db running on SQL server 2000. I want the user to be able to do a google-like search, which returns all records containing all given keywords specified by the user in any of the fields, example:
Table has the fields: id, fruit, color
User enters: apple pear green
The query should return all records that contain apple AND pear AND green in any of the fields.
Now I do it like this:
SELECT * FROM table WHERE (fruit LIKE '%apple%' OR fruit LIKE '%pear%' OR fruit LIKE '%green%') AND (color LIKE '%apple%' OR color LIKE '%pear%' OR color LIKE '%green%')
this query works fine, but since my actual table contains about 10 fields that have to be searched, the query get's quite huge, especially when 2 or more keywords are given.
Question: is there an easier way to achieve this?
(this is what my query actually looks like, using the keywords dekker warmenhuizen 0226:)
SELECT
tKlant.nKlant AS nKlant,
MAX(sAchternaam) AS sAchternaam,
MAX(sVoornaam) AS sVoornaam,
MAX(sVoorletters) AS sVoorletters,
MAX(sBedrijfsnaam) AS sBedrijfsnaam,
MAX(sPlaats) AS sPlaats,
MAX(sStraat + ' ' + sHuisnummer) AS sAdres,
MAX(sPostcode) AS sPostcode,
MAX(sCommunicatie) AS sCommunicatie,
(CASE DATALENGTH(mOverig) WHEN 0 THEN 0 ELSE 1 END) AS HasOverig,
MAX(sKlantGroep) AS sKlantGroep
FROM tKlant
LEFT JOIN tKlantGroep ON tKlant.nKlantGroep = tKlantGroep.nKlantGroep
LEFT JOIN tCommunicatie ON tKlant.nKlant = tCommunicatie.nKlant
LEFT JOIN tAdres ON tKlant.nKlant = tAdres.nKlant
WHERE (tKlant.sAchternaam LIKE '%dekker%' OR tKlant.sBedrijfsnaam LIKE '%dekker%' OR tKlant.sKlant LIKE '%dekker%' OR tKlant.sVoornaam LIKE '%dekker%' OR tKlant.mOverig LIKE '%dekker%' OR tCommunicatie.sCommunicatie LIKE '%dekker%' OR tAdres.sStraat + ' ' + tAdres.sHuisnummer LIKE '%dekker%' OR tAdres.sPostcode LIKE '%dekker%' OR tAdres.sPlaats LIKE '%dekker%' OR tKlantGroep.sKlantGroep LIKE '%dekker%')
AND (tKlant.sAchternaam LIKE '%warmenhuizen%' OR tKlant.sBedrijfsnaam LIKE '%warmenhuizen%' OR tKlant.sKlant LIKE '%warmenhuizen%' OR tKlant.sVoornaam LIKE '%warmenhuizen%' OR tKlant.mOverig LIKE '%warmenhuizen%' OR tCommunicatie.sCommunicatie LIKE '%warmenhuizen%' OR tAdres.sStraat + ' ' + tAdres.sHuisnummer LIKE '%warmenhuizen%' OR tAdres.sPostcode LIKE '%warmenhuizen%' OR tAdres.sPlaats LIKE '%warmenhuizen%' OR tKlantGroep.sKlantGroep LIKE '%warmenhuizen%')
AND (tKlant.sAchternaam LIKE '%0226%' OR tKlant.sBedrijfsnaam LIKE '%0226%' OR tKlant.sKlant LIKE '%0226%' OR tKlant.sVoornaam LIKE '%0226%' OR tKlant.mOverig LIKE '%0226%' OR tCommunicatie.sCommunicatie LIKE '%0226%' OR tAdres.sStraat + ' ' + tAdres.sHuisnummer LIKE '%0226%' OR tAdres.sPostcode LIKE '%0226%' OR tAdres.sPlaats LIKE '%0226%' OR tKlantGroep.sKlantGroep LIKE '%0226%')
GROUP BY tKlant.nKlant, DATALENGTH(mOverig)
ORDER BY sAchternaam, sPlaats, sAdres;
KEYIDGROUP 1 1 a 2 1 b 3 2 a 4 2 b 5 3 a 6 3 b 7 4 a 8 5 a
This is my simple table I need a query that will identity the ID's that are missing the group "b" but I don't want ID 1,2,3 to come up because they are part of a and b. I just need to see anything missing only "b" but not if it's part of a and b.
query should reveal answer should be missing the group b KEYID 7 4 8 5
I tried the NULL search but since the records don't exist it cant find a null. I am writing a query to identify the missing ID without B but exclude ID that are part of A and B
Hi, Using Visual Web Developer and SQL Express, (coding in Csharp) I want to add a advanced search facility to my site. Problem is I do not know how to begin. The website is a business directory and displays company names and services that they provide. Here is where I am at.... So far I have made one query which allows users to search the database by "town" such as if they enter "London" in the text box, it returns the relevant records into a gridview. Rather than have a seperate text box for each query, I want to provide an advanced search box option so users can define their search and query the database by various criterias, such as geography, sector, name, number of employees in companies etc. I have seen compact advanced search boxes on many sites!. Replies greatly appreciated. prontonet
HIi want to create a procedure, basically i'll have 4 input parametres (Title, Category, ReleaseClass and BuyPrice)title will come from a textbox, the rest from dropdownlistsif a user enters a title, selects a ReleaseClass and BuyPrice, But doesnt select a category, all categories should be returned - You know what i meanhow do i go about this - Any Ideas??Cheers!!!
Have searched a good bit for a KB or other article but haven't been able to find one.
I have a 2003 server with SQL Server 2005 Express installed, but not the Advanced Services version. Recently installed an application that needs the Full Text search capability. Would prefer not to remove SQL Server Express and reinstall the Advanced version because I'm also using Symantec Backup Exec 11d which has its own instance on the SSExpress installation.
Is it possible to upgrade an instance to Advanced Services? If not, is it possible to upgrade the entire install?
There's got to be a how-to article somewhere on how to do this. Just can't seem to locate it at Microsoft or with Google.
I have upgraded a SBS 2003 MSDE database (instance MSSQL$SHAREPOINT) to SQL Server 2005 Express Advanced Edition. This worked without a problem even when I enabled all the options for the upgrade including Full-text search.
I now want to have Full-text search on this instance of SQL 2005 with database name of STS_EVEREST_1.
I first tried to use the T-SQL command of "CREATE FULLTEXT CATALOG BBVisionCatalog AS DEFAULT;" I now know that the original database was created under SQL 2000 and therefore I needed to use SQL 2000 commands. So I used the following script:
USE STS_EVEREST_1 EXEC sp_fulltext_database 'enable' EXEC sp_fulltext_catalog 'BBVisionCatalog', 'create';
It produced the following ERROR messages:
(1 row(s) affected) Msg 7609, Level 17, State 2, Procedure sp_fulltext_database, Line 46 Full-Text Search is not installed, or a full-text component cannot be loaded.
I checked to see if the Microsoft Search Service was running. It was running.
Hi. I'm trying to get full-text search working on my SQL 2005 Express with Advanced Services and am having problems. I thought that I installed it correctly, and when I look in the services running, I see it SQL Server Fulltext Search(MSSQLSERVER). Also note that I have SQL Server 2005 Standard installed on this same laptop. I don't know if that Full text Search applies to the Standard, Express or both.
What I do see is that if I connect to the database engine named <mylaptop>, I can see the version is 9.0.1399 and I can see the check box to enable full-text indexing in a particular databases properties. When I run SELECT FULLTEXTSERVICEPROPERTY('IsFullTextInstalled'), I get a 1.
However, when I connect to the engine name <mylaptop>SQLExpress, I se the version is 9.0.3042, and I don't see the same check-box to enable full-text indexing. When I run SELECT FULLTEXTSERVICEPROPERTY('IsFullTextInstalled'), I get a 0.
I've never tried this before so I know I'm probably missing something basic. But, I have searched quite a bit and not found my answer. So, I'm looking to you for help.
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
I want to query a database through a ASP.NET page and I want to set the page up like an advanced search page would look. My question is, how do I write the stored procedure and/or what value do I pass from ASP.NET to accomplish null or blank values. For instance, if someone wants to query by TRIP id and not vehicle ID then how do I write the where claue?
I have the following figured out, however what I want to do is almost come up with a new column based on if the row actually exists in the employeeeval column: SELECT e.DeptID, e.LastName + ', ' + e.FirstName AS EmpName, e.EmployeeID, u.UserName FROM Employee e LEFT OUTER JOIN EmployeeEval ev ON e.EmployeeID = ev.EmployeeID LEFT OUTER JOIN [User] u ON u.Department = e.DeptID WHERE (u.RoleID = 'supervisor') AND (e.CompanyID = @CompanyID) AND (e.FacilityID = @FacilityID) AND (ev.PersonalScore IS NULL) ORDER BY e.DeptID, e.LastName so in my select I want to add something like ev.approved which then that brings back either Null or 0. Then based on that create a variable to bring back as a string and if it = 0 make my string say 'In Progress' and if it's Null, say 'Not Started'. I would imagine I would need a Declare @Status nvarchar(15) --- but I get lost after that b/c wouldn't I need some sort of way to count throught the rows of my result set and do an IF statement? I can't quite figure this process out, after numerous attempts.
I want to run a query overnight through the SQL agent using osql. However I need to turn off the print header option that you normally turn off through the advanced options tab in the Query Analyzer. Does anyone know if this is possible?? Many Thanks in advance..
SELECT item.name AS name, t15.f167 AS start, t15.f168 AS end, t15.f180 AS organizer FROM item, t15 WHERE item.row_id = t15.id AND t15.f167 > getDate() UNION ALL SELECT item.name AS name, t30.f221 AS start, t30.f222 AS end, '<a class=kalender_link href=http://www.xxx.no/default.asp?V_ITEM_ID=' + item.id + '> KAN < / a > ' FROM item, t30 WHERE item.row_id = t30.id AND t30.f221 > getDate() ORDER BY start DESC
The problem is the organizer field. I need to generate an url, but I get all sorts of problems with data types, ie. you can convert an int into ntext.
So the question is basically, how do I get the following to work:
'<a class=kalender_link href=http://www.xxx.no/default.asp?V_ITEM_ID=' + item.id + '> KAN < / a >'
Hi,This is my basic sql shape query:------------------------------------------------------------SHAPE {select * from tbl1}APPEND({SELECT * FROM tbl2 where field1=1} AS RS2 RELATE field TOfield)------------------------------------------------------------With this query i get a RecordSet (RS1), who handle all the recordsfrom table tbl1, and a secondary RecordSet (RS2) who handle all therecords from table tbl2, who applies to the criteria that field1=1.It is possible that RS2 will be empty (zero records) since there is norecord in tbl2 who applies to that criteria.My wish is to design a query, that will collect only the records fromtbl1, that will have records from tbl2 who applies to the criteria -that RS2 won't be empty !I want to influence on the main part of the query (RS1), through thecriteria that is being used in the secondery query (RS2).I hope that my question is clear enough. thanks !
Dear Expert,I have 2 tables as the following,Table : ProductColumn : ID, Code, NameTable : TrxColumn : Trx_ID, Trx_Date, Product_IDHow can perform the following query in MSSQL or is there any other wayto perform the same query ??? For you info I can do this in Sybase andit's work fine. Thank you.================================================== ==========Select Trx.Product_ID,(Select Produc.CodeFrom ProductWhere Product.ID = Trx.Product_ID) as Product_CodeFrom TrxWhere Product_Code = '0001'================================================== ==========Regards,Chen Fock Siong2004-05-27
THIS LOOKS LIKE A LOT BUT I JUST WANTED TO GIVE ALL INFORMATION NEEDED FOR YOU TO EASILY ASSIST ME. I am not good with SQL so please bare with me. I will give a dumbed down table for us to work with:timestamp - DATA1 - DATA2 - MAXVALUENEEDED - DATA32006/8/12 12:00 123 125 1289 121 2006/8/12 12:05 124 128 1291 1232006/8/15 12:00 130 128 1190 1242006/8/15 1:00 131 127 1196 123 The columns labeled DATA do not really matter. The only important ones are timestamp and MAXVALUENEEDED but I do need the query to return all columns. What the query has to do: The query needs to find the MAX of MAXVALUENEEDED for a given DAY. Example Output- 2006/8/12 124 128 1291 1232006/8/15 131 127 1196 123As you can see the MAX values were grabbed for each given day and the unique records were returned on a per day basis. My current SQL Query is: SELECT CONVERT(varchar, timestamp, 101) AS Time, CONVERT(int,LV50AEPM_AMPS_A_VAL0) AS AMPS_A, CONVERT(int,LV50AEPM_AMPS_B_VAL0) AS AMPS_B, CONVERT(int,LV50AEPM_AMPS_C_VAL0) AS AMPS_C, CONVERT(int,LV50AEPM_KVA_TOT_VAL0) AS KVA_TOTAL, CONVERT(int,LV50AEPM_KW_TOT_VAL0), CONVERT(int,LV50AEPM_VLL_CA_VAL0), CONVERT(int,LV50AEPM_VLL_BC_VAL0), CONVERT(int,LV50AEPM_VLL_AB_VAL0) FROM Table_1 T1 WHERE CONVERT(int,T1.LV50AEPM_KVA_TOT_VAL0) = (SELECT MAX(CONVERT(int,T2.LV50AEPM_KVA_TOT_VAL0)) FROM Table_1 T2 WHERE CONVERT(varchar,T1.timestamp,101) = T2.timestamp) ORDER BY Time ASC The problem is it only returns the max value for one day instead of all days. Can anyone help me correct this? Thanks in advance for your help.
I need to select a list of products based on a complex criteria. First off, here is a list of the tables I am using and their function.
Dbo.Products – This table holds product names and information.
Dbo.Products_Attributes – This table holds a list of attributes for each product. It has a many to 1 relationship with Products. This table holds only 2 fields – ProductID and AttributeID
Dbo.Customers – This table holds basic customer information and some of the needed criteria for the product search.
Dbo.Customers_Attributes – This table contains a list of attributes that the customer needs in his/her products. This table has a many to 1 relationship with Customers and only has 2 fields, CustomerNum and AttributeID
Dbo.Attributes – This table contains all of the different attributes possible for our products to have. Each can be used by a customer when choosing criteria.
Background: Each attribute is a True / False. Either they want that attribute, or they do not care if they get it or not. This is where the hard part comes in. If a particular attribute is listed as needed in dbo.Customers_Attributes, then I do not want any records pulled from Products that DOES NOT have this attribute. On the other hand, if the attribute is NO listed in the customers_attributes list, it is assumed that the customer wants it. In other words, if there were NO attributes in the customers_attributes list, ALL products would be returned. Attributes listed in the customers_attributes table are “required� (no product will be returned that does not have what is in the list).
I hope I was clear enough… I had to change the table names a functions slightly because of some stupid policy about giving out too much proprietary information here.
If any of you know how to do the above with a subquery of some kind, please let me know.
SQL Sever 2012, I have a table where I store data related with a Log, the columns of the table are three, IDTable, DateLog and CountLog, the column CountLog is a cumulative value, each new rows can increment this value, my query will receive two parameters related with the Date,  @dateFrom and @dateTo, with this information is necesary to get the diff between two months, for example:
CREATE TABLE MyTable (  IDTable INT IDENTITY NOT NULL,  DateLog  DATE NOT NULL,  CountLog INT NOT NULL )
[code]....
In this case I need to apply a filter with the Dates:
@dateFrom ='2014-01-01', @dateTo   ='2014-04-28'
But according with this filter I need to limit the results only for this period between the date, but I need that the first month (January 2014) take the information of the max value from previous month even not included in the filter, in this case the results will be the next:
Id     MonthYear    Diff 1       Jan2014    5 2       Feb2014    3 3       March2014  0 4       April2014    5
With the results, for the first mont (January) is, according to the range of times, January is the lower limit,the last cumulative value of CountLog before the first month of the range  was 2 (December 2013), the max value of the CountLog for this first month was 7, the diff is 7-2 equal to 5 , in the case of the next month (February) the max value of the CountLog was 10, the diff is 10 - 7 equal to 3 and this way. Â
I have 2 TableAuthorsID Name1 Clint2 Voke BooksBookID ID BookName Price1 1 Book1 10 2 1 Boo21 12 3 2 Book3 6 4 1 Book4 13 5 1 Book5 2 Now I want to List All Authors and only show Most Expensive book Name of each Author.So I need this Fields :ID,Name,BookName,BookID,Price. How could I Write SQL query For It (I want to show results in DB Without Using SP).I want to Create NEw Views Which Shows my required Results. thanks,
This is a fairly detailed problem, so this will be a long post... I do appologize. I have been agonizing over this now for over a week and cannot find a viable solution. Hopefully one of you can help.
First off, I work for a realestate company, and this query will display a list of properties based on a number of different criteria and criteria types. There are multiple tables involved:
dbo.Prop: Property Database. Holds basic info about each property
dbo.Prop_Features: holds all the features (such as Pool, Carpet, Drapes etc) for each property. The only information stored in this table are PropID and FeatureID (PropID being the Identity of the Prop table, FeatureID being the Identity of the Features Table)
dbo.Features Holds information on each possable "feature" in the system.
dbo.Members Holds basic information and criteria for each of our members.
dbo.Members_Features This table holds the MemberID and FeatureID where members have chosen one ore more features to be used for criteria when searching for a property.
Ok, now... That said, here is my problem. The query I had written (by a professional hired thru Robert Half Technologies) takes over 30 seconds to execute. I will post a copy of that SP below. This is unacceptable. We have to process thousands of these per hour, and a 30 second process time is very bad. Can any of you give me a idea of how to better approach this problem?
In the code below, you will notice there are other tables I did not mention - they are not important. The Speed problem is surrounding a single function, which I will mention below.
CREATE PROCEDURE dbo.Member_Get_List ( @MemberID Int, @UpdatesOnly Bit
SET @PropCount = (SELECT Count(*) FROM Members_Features WHERE MemberID = @MemberID ) END
IF @PropCount = 0 BEGIN
SELECT Top 100 P.PropID, P.Bedrooms, P.Baths, P.Garage, PT.PropName, P.Rent, P.Address, P.Xstreets, 'DateAvailable' = CASE WHEN DateDiff(Day, P.DateAvailable, GETDATE()) < 0 THEN 'NOW!' ELSE CONVERT(varchar(10), P.DateAvailable, 101) End, P.Lease, dbo.Prop_Get_Feature_List_Fun(P.PropID) + CASE Len(P.CustomFeatures) WHEN 0 THEN '' ELSE ', ' + P.CustomFeatures End + CASE Len(P.Comments) WHEN 0 THEN '' ELSE ', ' + P.Comments End as 'Features', P.Deposit, Phone1 = SUBSTRING(L.Phone1, 1, 3) + '-' + SUBSTRING(L.Phone1, 4, 3) + '-' + SUBSTRING(L.Phone1, 7, 4), A.AreaName, Z.County, Z.City, Z.State
FROM Prop P
INNER JOIN Area_Zipcode AZ
ON P.Zip = AZ.Zipcode
INNER JOIN Area_Areas A
ON AZ.AreaID = A.AreaID
INNER JOIN Members_Areas MA
ON A.AreaID = MA.AreaID
INNER JOIN Members_PropTypes MP
ON P.PropType = MP.PropType
INNER JOIN Prop_Types PT
ON P.PropType = PT.PropType
INNER JOIN LandLords L ON P.LandLordID = L.LandLordID
INNER JOIN ZipCode Z ON P.ZIP = Z.ZipCode
WHERE
P.Active = 1 AND P.Rent BETWEEN @RentMin AND @RentMax AND P.Bedrooms BETWEEN @BedMin AND @BedMax AND P.Baths >= @MinBaths AND P.Garage >= @MinGarage AND P.Acreage >= @Acreage
AND MA.MemberID = @MemberID AND MP.MemberID = @MemberID
AND P.ListDate > Case @UpdatesOnly When 0 then '01/01/1900' When 1 then @LastUpdate End
CREATE TABLE #Prop ( PropID int, Bedrooms tinyint, Baths float, Garage float, DisplayText varchar(75), Rent float, Address varchar(100), Xstreets varchar(100), DateAvailable varchar(10), Lease tinyint, Features Varchar(3500), Deposit float, Phone1 varchar(12), AreaName Varchar(50), County Varchar(30), City Varchar(30), State Varchar(75) )
DECLARE curProp Cursor FORWARD_ONLY for
SELECT Top 100 P.PropID, P.Bedrooms, P.Baths, P.Garage, PT.PropName, P.Rent, P.Address, P.Xstreets, 'DateAvailable' = CASE WHEN DateDiff(Day, P.DateAvailable, GETDATE()) < 0 THEN 'NOW!' ELSE CONVERT(varchar(10),P.DateAvailable, 101) End, P.Lease, dbo.Prop_Get_Feature_List_Fun(P.PropID) + CASE Len(P.CustomFeatures) WHEN 0 THEN '' ELSE ', ' + P.CustomFeatures End + CASE Len(P.Comments) WHEN 0 THEN '' ELSE ', ' + P.Comments End AS 'Features', P.Deposit, Phone1 = SUBSTRING(L.Phone1, 1, 3) + '-' + SUBSTRING(L.Phone1, 4, 3) + '-' + SUBSTRING(L.Phone1, 7, 4), A.AreaName, Z.County, Z.City, Z.State
FROM Prop P
INNER JOIN Area_Zipcode AZ
ON P.Zip = AZ.Zipcode
INNER JOIN Area_Areas A
ON AZ.AreaID = A.AreaID
INNER JOIN Members_Areas MA
ON A.AreaID = MA.AreaID
INNER JOIN Members_PropTypes MP
ON P.PropType = MP.PropType
INNER JOIN Prop_Types PT
ON P.PropType = PT.PropType
INNER JOIN LandLords L ON P.LandLordID = L.LandLordID
INNER JOIN ZipCode Z ON P.ZIP = Z.ZipCode
WHERE
P.Active = 1 AND P.Rent BETWEEN @RentMin AND @RentMax AND P.Bedrooms BETWEEN @BedMin AND @BedMax AND P.Baths >= @MinBaths AND P.Garage >= @MinGarage AND P.Acreage >= @Acreage AND MA.MemberID = @MemberID AND MP.MemberID = @MemberID
AND P.ListDate > Case @UpdatesOnly When 0 then '01/01/1900' When 1 then @LastUpdate End
dbo.Prop_Get_Feature_List_Fun(P.PropID) + CASE Len(P.CustomFeatures) WHEN 0 THEN '' ELSE ', ' + P.CustomFeatures End + CASE Len(P.Comments) WHEN 0 THEN '' ELSE ', ' + P.Comments End AS 'Features',
This function is the cause of the speed problem, methinks. When run alone, it takes 29 seconds to process with the same MemberID that takes about 33 seconds to process completely (the whole Proc). This function simply returns a list of comma delimited features for each property, for displaying on a customer list. Here is that function:
CREATE Function dbo.Prop_Get_Feature_List_Fun (@PropID int) RETURNS Varchar(3500)
AS BEGIN
Declare @FeatureList Varchar(3500)
select @FeatureList = Coalesce(@FeatureList + ', ', '' ) + F.FeatureName FROM Prop P
INNER JOIN Prop_Features PF
ON P.PropID = PF.PropID
INNER JOIN Features F
ON PF.FeatureID = F.FeatureID
WHERE
P.PropID = @PropID
ORDER BY
F.FeatureName
Set @FeatureList = isnull(@FeatureList,'Please call for features.')
RETURN @FeatureList END
Now, I know I probably gave lots more information then needed to solve this issue - but its better to have too much then not enough.
Any help at all in speeding up this function or describing another way to do this would be most appreciative.
I graduated from college about three years ago and have been working as a programmer using MS SQL 2000 and even though I've learned a TON in these past three years I know there is tons more I can learn.
Because my company uses Microsoft SQL Server 2000 I'd like to focus on that, but anything ANSI-SQL is perfectly fine.
So... what are some good books on SQL query optimization and other advanced SQL topics?
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?
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
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
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
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 (
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
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)
[OpporID] [numeric](18, 0) IDENTITY (1000, 1) NOT NULL , [OpportunityID] [varchar] (16) COLLATE SQL_Latin1_General_CP1_CI_AS NOT NULL , [OpportunityTypeID] [numeric](10, 0) NOT NULL , [SLABased] [int] NOT NULL , [LoginID] [nvarchar] (50) COLLATE SQL_Latin1_General_CP1_CI_AS NOT NULL , [DateCreated] [datetime] NOT NULL , [AccountID] [int] NOT NULL , [GeographyID] [int] NOT NULL , [VerticalID] [int] NOT NULL , [BDMID] [int] NOT NULL , [Probability] [int] NOT NULL , [PASStatus] [int] NULL , [InsertedDate] [datetime] NULL , [InsertedBy] [varchar] (50) COLLATE SQL_Latin1_General_CP1_CI_AS NULL , [UpdatedDate] [datetime] NULL , [UpdatedBy] [varchar] (50) COLLATE SQL_Latin1_General_CP1_CI_AS NULL , [UpdatedFlag] [int] NULL
and SKILL [SkillNo] [numeric](18, 0) IDENTITY (1, 1) NOT NULL , [OpportunityID] [numeric](18, 0) NOT NULL , [OrderId] [numeric](18, 0) NOT NULL , [PracticeID] [int] NULL , [SkillID] [int] NOT NULL , [NoOfPeople] [int] NOT NULL , [Clientinterview] [int] NOT NULL , [Location] [int] NOT NULL , [JDAttached] [int] NOT NULL , [JDFilePath] [varchar] (50) COLLATE SQL_Latin1_General_CP1_CI_AS NULL , [Status] [int] NULL , [Experience] [int] NULL , [InsertedDate] [datetime] NULL , [InsertedBy] [varchar] (50) COLLATE SQL_Latin1_General_CP1_CI_AS NOT NULL , [UpdatedDate] [datetime] NULL , [UpdatedBy] [varchar] (50) COLLATE SQL_Latin1_General_CP1_CI_AS NULL , [UpdatedFlag] [int] NULL , [GeoLocation] [int] NULL )
i want to make a stored procedure for custom search on these two tables with the following fields given to the user as an option to make his choice.. from opportunity table - OpportunityTypeID,SLABased,AccountID , GeographyID, VerticalID, BDMID, Probability
and from skill table SkillID, Location, GeoLocation
Hi!In short description I want to make table with Articles and search Query for this table like there is search engine at templatemonster.com with templates and categories. Basicly I have table:- id - cat_name- 1 - Software- 2 - Hardware- 3 - Games- 4 - Internet- 5 - Events etc.And for example Article is in Software, Games and Events category, "1,3,5".Now user select to show articles in Games and Events categories, so "3,4,5"How write this search query? I don't have idea.
Hi, I'm wondering about the following: I have come across an InfoPath Forms application who's code is scripted in javascript and who's data seems to be in XML files.An analyst at that company told me they suspect the data is ALSO in SQL Server... somewhere. They can't seem to find it though. I havereviewed the .js code and some methods are called for which I can find no source. I believe those methods execute OK because they're foundinside some DLL. I'm thinking I would enter a new record using the form in InfoPath using some datavalue that I can expect will be unique.. like a lastname who's first three chars is ZZZ or something like that. Subsequently, I'd search each column in each table in each DB on the server to see if I can locate it somewhere. So, my question is what is the best approach for this? I have access to the db, table and column names. I know I can write a small vb.net piece of code to execute my search. But, is there some better way using some sql procedure (or using the full text catalog) instead or any other tool(s)? Thanks in advance for your advise. Stewart
Hi everyone, I'm trying to implement SQL Server database search. The details are:-1. I have table called EMPLOYEE has FNAME,LNAME etc cols.2. User might look for any employee using either FNAME or LNAME3. I have search box in asp.net where user could enter search stringThe sample data:FNAME LNAMEabc georgedef georgerkis litarose lita The query i wrote:SELECT * FROM EMPLOYEE WHERE lname like '%' + searchArg + '%'My problem is:-1. let's say user is looking for employee "george"; In search string instead of typing actual word "george", user could type "jeorge"; because the name pronounce or sounds like similar.Same thing with user could type "leta" instead of "lita". Again these are all similar sounds. When you look for "jeorge" in GOOGLE; it says "did you mean george"; i would like implement something like that. somewhere i saw SOUNDEX would do what i am looking for; but i no luck for me. Is this possible anyway in T-SQL or Fulltext search. Your help is greatly appreciated. ThanksBob