0

I'm trying to create a search text-box on my website than when submitted will pass the 'string-keyword' into my grid and pull all matching records for that keyword.

I'm having to setup my grid with a where statement that will "listen" for parameters passed in by the form via query-string.

I'm not sure how to approach this. Any insight, tips, examples appreciated.

UPDATE------- This is the query my grid is using to populate records. In addition to City/Region/Country I'm trying to incorporate a keyword Search that would only look at my 'Company' Field inside the BND_Listing table.

select * FROM BND_listing right join BND_ListingCategories
on BND_Listing.CatID=BND_ListingCategories.CatID
where 
 (CategoryName = '[querystring:filter-Category]' or '[querystring:filter-     Category]'='All')
 and
 (City = '[querystring:filter-City]' or '[querystring:filter-City]'='All')
and
(Region= '[querystring:filter-State]' or '[querystring:filter-State]'='All')
and
(Country= '[querystring:filter-Country]' or '[querystring:filter-    Country]'='All')
and
isnull(Company,'') <> ''
ORDER by Company ASC
UserSN
  • 953
  • 1
  • 11
  • 33

1 Answers1

1

I don't know what you mean by "listen" for parameters, but since you only have TSQL tagged, the matching part in SQL Server is achieved like so:

DECLARE @param VARCHAR(256)   --or what ever size you need
SET @param = 'some text'

SELECT SomeColumns
FROM SomeTable
WHERE aColumn LIKE '%' + @param + '%'

Or using SqlCommand in VB you can check out: https://stackoverflow.com/a/251311/6167855

Community
  • 1
  • 1
S3S
  • 24,809
  • 5
  • 26
  • 45
  • thanks for this example. I'm going to have to spend a little time reading to understand whats going on. I have to modify this to pull tokens from my application. Will update once I get it working. – UserSN Sep 22 '16 at 19:15
  • 1
    What's being passed in? What's the token look like in the DB? @AlexP – S3S Sep 23 '16 at 11:54
  • my forms allow me to run a query and add a query-string parameter such as ?keyworkd=[Field1] where field1 would be replaced with whatever was inputted into the search box. From this I would need to modify my grid's where statement to pull anything that matched [field1] from my tables "Company Name" field and return only those results. This is how I imagine I could make it work? That's what i've done so far for city/state/region only difference those were select boxes this is a search box where they can input a string that might not necessarily match exactly 1 or many rows of data. – UserSN Sep 24 '16 at 15:34
  • 1
    It'll still need to be select. You can make the search field optional in the select by using `WHERE @param IS NULL or [Company Name] LIKE '%' + @param + '%'` – S3S Sep 24 '16 at 15:45
  • Error: Must declare the scalar variable "@param". Is that an amalgamation of tsql & some other coding language? – UserSN Sep 24 '16 at 15:56
  • Apologies for these newb questions i'm in the process of learning programmatic languages – UserSN Sep 24 '16 at 15:57
  • That's a SQL error. What's does your SQL code look like? Can you add it to your original post. – S3S Sep 24 '16 at 16:01
  • I just simply tried to pull this into SQL MS too see if it would pull any results by replacing [CompanyName] with a value just as my module would. [ Using select * from BND_Listing. ] Let me try modifying my codes and trying directly on the site. – UserSN Sep 24 '16 at 16:04
  • I added my query that is currently working with my City/Region/Country filters that look at my querystring. I added now a &search=[Company] to my submission form. The code you've mentioned how would I make it only look at my 'Company' Column? – UserSN Sep 24 '16 at 16:11