Wildcard In Simple Sql Search.
Mar 30, 2005
I'm very new to SQL so please forgive my ignorance...
I've made a simple .net search page which queries an sql database with the following query, (in a stored procedure):
SELECT Category, Number, RegisteredUser, DeptName, Surname, Forename, Site, IDFROM tblTelephonesWHERE (@surname IS NULL OR Surname LIKE @surname) AND (@site IS NULL OR Site = @site) AND (@deptname IS NULL OR DeptName LIKE @deptname)
This works fine, as expected if i leave fields null or enter an exact match, but I (of course) have to add a wildcard in my search string for a wildcard search. For example, looking for 'duncan' i need to enter 'du%' or 'duncan'.
What I really want is for all searches to have wildcards behind them so only the first few characters need be inputted, and I could just search for 'd' or 'dun' without adding the '%' to get 'duncan'. I think I am aware of the implications of this approach and do want to go ahead as there are only about 850 records.
Any help or links to useful articles would really be greatly appreciated.
View 1 Replies
ADVERTISEMENT
Dec 15, 2005
Hi all, I am currently using SQL Server 2000and am having some issues when searching a CHAR column and using the WildCard character '%'. The problem is that when I use this WildCard character, the results returned (if any!) are incorrect. For example, I know that there are many rows in the DB that have the following data in a column, 'ABERYSTWYTH CEREDIGION', but when I using the following SQL...'(WHERE (UPPER(AddrLine3) = 'ABERYSTWYTH%')' I get no results returned.Is there a known issue with the WildCard character in SQL Server 2000?ThanksTryst
View 3 Replies
View Related
Mar 24, 2008
Hi someone please help me.
i have a serach page which have 4 textboxes.
passing this textboxes as parameters to storedproc iam searching the value.
filling atleast one textbox should fetch the value.
i have stored proc for searching it using normal column values but i want it do using wildcard search also.
set ANSI_NULLS ON
set QUOTED_IDENTIFIER ON
go
ALTER PROCEDURE [dbo].[search1]
(@val1 varchar(225),
@val2 varchar(50),
@val3 varchar(50),
@val4 varchar(50))
AS
BEGIN
DECLARE @MyTable table (CNo varchar(255))
INSERT @MyTable
Select CNo From customer where
((@val1 IS NULL) or (CNo = @val1)) AND
((@val2 IS NULL) or(LastName = @val2)) AND
((@val3 IS NULL) or(FirstName = @val3)) AND
((@val4 IS NULL) or(PhoneNumber = @val4))
--Now do your two selects
SELECT c.*
FROM customer c
INNER JOIN @MyTable T ON c.CNo = T.CNo
Select r.*
From refunds r
INNER JOIN @MyTable t ON r.CNo = t.CNo
END
I WANT THE SEARCH TO BE DONE FOR WILD CARD CHARACTERS ALSO.
if the user enters lastname s*
using same storedproc can i insert wildcard search.
how can i do that please some one help me.
thanks
renu
View 1 Replies
View Related
Jul 25, 2000
Hi,
I have a doubt about using a wildcar(% or *).
Can we use the the wildcard in query in the following way...
Select name from abcd where
(name like'%moh%'or name like '%raj%'or name like '%san%')
Is it allowed to use the wildcard at the biginning of the string. If any one says yes :Using the full text search is it possible to improve the query performance.
I thinking of that it is not allowed to use the wildcard at the beginning of the string.
Your comments and recommendation will be highly appreciated...
Thanks,
Mohammed.
View 1 Replies
View Related
Feb 1, 2004
hello,
i want to search for "any phrase here*" where i want it to match the exact same phrase and followed by anything. but the problem is that when using the following syntax: contains(myTbl,'"my phrase here*"') i will get results like "my123 phrases here" so the wildcard will be applied to the consecutive words and not the last word.
How can i search for an exact phrase followed by anything?
ps: i cant omit the wildcard becoz the last word is not exact
so treating the space as any other character and not as a seperator in the search_expression may be a solution but how to do it
Thanks
samham
View 5 Replies
View Related
May 8, 2006
Hi All,
I have a company table with CompanyName and Address details.
In the Company Name field - I have got companies with names like - 'The 1% Club', '99% Pure Water', 'The 1% Golfer' etc...
I want to search for Companies with % using the LIKE clause - Say for ex.
SELECT CompanyName from Company WHERE CompanyName LIKE 'The 1%%'
I was expecting the above query to return - All Companies starting with 'The 1%' - So from the above list - I expected it to return - 'The 1% Club' and 'The 1% Golfer'.
Unfortunately the query isn;t accepting % in the WHERE LIKE clause except for the wildcard character.
Is there a way out to escape the Wildcard Characters present in the Field Values while searching.
Thanks,
Loonysan
View 4 Replies
View Related
May 16, 2007
Is it possible to do a wildcard search on an encrypted column?
Many thanks!
View 6 Replies
View Related
Nov 26, 2007
Hi there,
I am trying to get the do a full text search using the CONTAINS operator and the asterisk wildcard prefix and apparently it is returning inconsistent results. I have a full-text enabled table named Content which contains an AutoId field with a clustering index built on it, a column named ContTitle which is fulltext indexed and a couple of other columns. The fulltext catalog has been fully populated.
When I perform this sample query:
SELECT AutoId, ContTitle FROM [Content] WHERE CONTAINS(ContTitle, ' "Live Band From Colombia" '),
it returns me a row, however when i change the sample query to include the asterisk wildcard behind the search phrase:
SELECT AutoId, ContTitle FROM [Content] WHERE CONTAINS(ContTitle, ' "Live Band From Colombia*" '),
it returns no rows.
I tried the to change the search phrase to "Excellence Service Award", for e.g.
SELECT AutoId, ContTitle FROM [Content] WHERE CONTAINS(ContTitle, ' "Excellence Service Award" '),
and
SELECT AutoId, ContTitle FROM [Content] WHERE CONTAINS(ContTitle, ' "Excellence Service Award*" '),
both queries will return rows with the content title Excellence Service Award
Does anyone know if I'm missing out on any anything, like the full text indexed is not populated correctly for e.g? It's just weird that the same kind of search will work on some rows and not for the rest. Thank you very much.
View 1 Replies
View Related
Jun 15, 2015
I am developing for a customer and they want a search facility that uses boolean logic and special characters. So they want to be able to add "AND" "OR" "NOT" "*" and "?". And for this to effect the search in the predicted way and ranked. I was wondering if there is any examples of this type of search implemented?
View 3 Replies
View Related
Jul 11, 2006
Hi, Im trying to create a simple search page to return a list of products from a table in a sql database. Id like to be able to search a product description column in a table I have called products using the contents of a text box. I was wondering how i can go about getting the search to check for all words the user types in rather than just a single word or an exact phrase. Im currently using the following sql query
SELECT [product_title], [product_description] FROM [products] WHERE ([product_description] LIKE '%' + @product_search + '%')
this works fine for single words and exact phrases but if i had product called 'fred w bloggs' and i enter 'fred bloggs' it will not return anything.
Please could anyone suggest how i shoud go about this?
Im not sure if my web hosting company will enable full text search or will this be required?
Thanks for any help!
pete_ (very new to asp.net!)
View 1 Replies
View Related
Feb 10, 2008
Hi all I need to implement a search function in Asp.net. Its nothing complicated, just find out whether a value exists in a particular table and return a boolean accordingly. However, the table has about 300,000 records. Is simply querying the table from the web (SELECT barcode FROM tblProducts where ID=123) the best way considering the releant column has been indexed.Any pointers would be appreciated. Thanks
View 4 Replies
View Related
Mar 16, 2008
Hello new in sql and asp.net here.I have this Select * from InvoiceHeader where TransactionDate > '03/16/2008' That code isn't working instead of returning a row with a transaction date that is greater than 3/16/2008 what it return is all the row. How can fix this? Thanks!
View 9 Replies
View Related
Mar 24, 2008
I have a table of articles:
-------------------------------------
Articles
-------------------------------------
ID | Date | Headline | Body
-------------------------------------
I'm trying to write a stored procedure that will search for a given keyword. Here's what I have:
CREATE PROCEDURE sproc_SearchArticles
(
@keyword varchar(50)
)
AS
SELECT ID, Date, Headline, Body
FROM Articles
WHERE Body LIKE %@keyword%
ORDER BY Date DESC
RETURN
That keeps giving me an error. If I put quotes around it, it will literally look for the term @keyword anywhere in the body.
View 1 Replies
View Related
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
Feb 1, 2008
Hello all, I am trying to build a simple search page using SQL Server 2005, Visual Web Developer in C#.I have enabled Full-Text Search on my DB and created the catalogs and indexes, but I am lost on the next step to build a search form that calls the data based on the users input in a textbox. Any suggestions? Thanks!Travis
View 3 Replies
View Related
Mar 26, 2008
I'm not trying to do anything too fancy; given a string, I just wanna see if anything in the column of my database matches the string. I'm using an SQL query that takes a string, then selects the data using LIKE %searchword%.This works fine when the user enters only one word. But I guess you can see that a problem arises when they enter more than one word.So how can I implement a very simple search that will take more than one word?
View 5 Replies
View Related
Mar 28, 2008
hello I have this code Select Waste.WasteName AS [Waste Name], InvoiceDetail.Volume, Branch.BranchLocation AS [Branch Location] From InvoiceHeader INNER JOIN InvoiceDetail ON InvoiceHeader.InvoiceNo = InvoiceDetail.InvoiceNo INNER JOIN Waste ON InvoiceDetail.WasteID = Waste.WasteID INNER JOIN Branch ON InvoiceDetail.BranchID = Branch.BranchID Where WasteName = 'Sludge' AND InvoiceDate >= '" + TextBox1.Text + "' AND InvoiceDate <= '" + TextBox2.Text + "'; The problem is everytime I will search for example InvoiceDate 03/27/2008, I need to add one day for example --> 03/28/2008 for me to be able to get that Invoicedate 03/27/2008.. What's do you think is the problem with my code? Thanks!
View 9 Replies
View Related
Mar 30, 2005
This question probably applies to Visual Web Developer but I don't know if it belongs in this Forum or that, sorry if you have to move it.
Hi there kind person reading this
I've created a stored procedure in SQL2000 that selects records where (name = @name) AND (site = @site). It works as I have tested it with Enterprise Manager.
I have also created a page with VWD that has a drop-down list populated with the site records and a text box. I have put an SQL data source on the page that is configured to select from the stored procedure. However, I can't set the @name and @site variables to collect from the ddl and txtbox through the wizard! I've tried selecting a Control as the source for @site but neither the ddl or txtbox appear in the control dropdown list. So I want to crack it with handwritten code.
Does anyone know of a post or article that can help me link the ddl and txtbox to a search button, which calls the stored procedure with the chosen variables allowing me to put the returned data into a gridview? I've been through a great walkthrough for VWD (Student Activities) but it doesn't seem to apply to the latest version - or there's something wrong with my (seems fine though) instalation. Thanks if you can help, I owe you a
View 3 Replies
View Related
Apr 15, 2008
I have a table of news articles:
-------------------------------------
Articles
-------------------------------------
ID | Headline | Article
-------------------------------------
I'm trying to write a search function that will search through the text in the Article column. Here's my stored procedure:
ALTER PROCEDURE sproc_SearchNews
(
@keyword varchar(50)
)
AS
SELECTID, Headline, Article
FROMArticles
WHEREArticle LIKE '%' + REPLACE(@keyword, '%20', '%') + '%'
RETURN
There's a few problems with this however...
1. If I enter "Dog" into the search, it will skip over the article if it contains "dog". I need to convert the search term and the article text to lowercase.
2. If I enter "iron" into the search, it will find articles containing "iron", but it will also find articles containing "environment". How can I fix that without affecting my multiple word search in the WHERE clause?
View 3 Replies
View Related
Jan 13, 2008
I have a table that has these columns:
LinkID, LinkURL, TimesRedirected
I have a webpage that keeps track of the url's of where the users are coming from. When they redirect to the page, the page will:
If the url of the previous page isn't in the database, add it
Otherwise, add to the TimesRedirected column.
View 6 Replies
View Related
Dec 7, 2004
Hello,
I have a search form in an ASP.NET/VB page. The form has the input text box and the button "search". The keywords are passed in the URL to results.aspx.
Here is an example of what I get in the URL, when I write the keywords "asp", "book" and "london" in the input text box and click "search":
results.aspx?search=asp%20book%20london
The database table has 3 fields: "id", "title" and "description".
I want to display all the records where at least one of the keywords is found in any of the 2 fields "title" and "description".
1. I suppose I need to get the words out of the URL to be used by SQL.
Maybe: string[] searchString = request.queryString("search").split('search'); ???
How can i make this run when page loads? I supose i need it. Right?
2. How should the SQL look? I supose i need to use the "Like" command
SELECT * FROM books WHERE title LIKE ...
But how to I use it if I can have 1, 2, 3, ... keywords?
Can someone help me?
Thanks,
Miguel
View 1 Replies
View Related
Sep 14, 2005
I'd like to build a simple search engine against Sql Server. Does .NET Framework provide some class to help in this task? From what I've heard there is an interface which implements it..
View 1 Replies
View Related
Mar 1, 2006
I am trying to write a simple search page that will search all the fields in a database to find all records that match a user input string. The string could happen anywhere in any of the fields. I have a dataset and can write a query but am unsure what the format is for this simple task. I figured it would look like this:
SELECT Table.*
FROM Table
WHERE * = @USERINPUT
But thats not working. Can someone help.? Thanks..
View 1 Replies
View Related
Apr 30, 2008
Hello ALl, can anyone please tell me how to search for NULLS.
like i know one method....
select * from table
where col = 'NULL'
View 1 Replies
View Related
Aug 8, 2006
I've got an nvarchar(max) column that I need to transform with some simple text processing: insert some markup at the very beginning, and insert some markup just before a particular regular expression is matched (or at the end, if no match is found).
Since the SSIS expression language doesn't support anything like this, is a Script Component the only way to go? Does Visual Basic .NET provide regular expression matching?
Thanks!
View 13 Replies
View Related
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
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
Jun 30, 2006
Hello everyone and thanks for your help in advance. I am working on an application that does a property search off of a database that contains approximately 40000 records. The search criteria allows the use to specify a minimum and maximum price, subdivision name, number of bedrooms, etc. I set up a stored procedure to query the databse. if one of the parameters is not specified, i simply pass it a "%". However, when i execute this sproc in Query Analyzer, it takes in excess of 10 seconds to return the records, even if only one or two are returned. I am assuming this is due to the use of the wildcard character when the user does not have a preference, but I am not sure of any other way to do this. Any help on this topic would be grealy appreciated.
View 3 Replies
View Related
Sep 9, 2006
hi,i have an sqldatasource a gridview and dropdownlistthe gridview is updated on the selectedIndexChanged Event of the dropdownlistmy goal is to add an item in the dropdownlist with the name ALLwhich should matches all the records in the databasei tried to put the value of the all item = * and % but neither seems to workany help on what could be going wrong would be appreciated
View 7 Replies
View Related
May 23, 2003
hi,
how do i contsruct a SQL query to search for the % character in a data field?
thanks
View 1 Replies
View Related
Oct 29, 2007
Is it a good idea to have multiple contains? I have this query:Select * from myTable where contains (Col1, 'Africa') or (Col2, 'Africa')Also, I tried this, didn't return anything:Select * from myTable where contains (Col1, 'Africa*') or (Col2, 'Africa')Both Col1 and Col2 has the string 'Africa' and 'African' in it.--sharif
View 2 Replies
View Related
Aug 22, 2006
alter procedure sp_ADsearch @tbname varchar(1000),@searchproduct nvarchar(500)
as
declare @sqlstr nvarchar(1000)
set @sqlstr='select * from '
set @sqlstr= @sqlstr + @tbname
set @sqlstr= @sqlstr + ' where name like '
set @sqlstr= @sqlstr + '%' + @searchproduct + '%'
exec sp_executesql @sqlstr
--
exec sp_ADsearch product,ee
when executing the procedure i am getting an error "Incorrect syntax near 'ee'.".
whats wrong with the syntax? how to use % along with variables
View 5 Replies
View Related
Dec 30, 2006
I am trying to control how users view records. I want to create a solution that would, for instance permit:user A to view Store 1user B to view store 2 and store 3user C to view store 5 and store 6and User D to view all stores even if more stores were added in the future (in other words user D would have access to all records)
I want to create an 'authorization table' so that different users can see different records. I think the easiest way to do this is to pass a parameter to the where clause, but the problem that I face is the how can I use a wildcard in a SQL 'IN' clause? Does anyone have any suggestions. Perhaps I am taking the wrong approach. I would appreciate any guidance.
View 2 Replies
View Related