If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Data Access, Manipulation & Batch Languages > ASP > ASP Search Syntax Question

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 10-02-03, 15:59
seberts seberts is offline
Registered User
 
Join Date: Oct 2003
Posts: 1
Question ASP Search Syntax Question

What I'm trying to do is have the search results show only records where dname = "LB Smith" but also give the user to input values for the other 2 variables. If nothing is found with the user variables it should show all values for "LB Smith".

The idea here is when a LB Smith user is using the database they can only see their records. Here's what I've used for my search critira:

select * from warrantyclaims where dname = '("LB_Smith"))' and attachserial like '%{Request.QueryString("keyword")}%' or cname like '%{Request.QueryString("keyword")}%'

NOTE: Keyword is the text box they enter the search term into. It works fine if I don't declare LB Smith in the code but that's not what I need ....

THANKS IN ADVANCE!!!
Reply With Quote
  #2 (permalink)  
Old 10-07-03, 08:49
Patrick Chua Patrick Chua is offline
Registered User
 
Join Date: Jul 2003
Location: Penang, Malaysia
Posts: 212
Do you mean when the user does not key in the 2 optional search criteria, u want to show all records cocerning dname="LB Smith" ?

If what I understand correctly,
first I need to know what database are u using? Is it just Access or MS SQL Server?

I'm not sure if Access SQL syantax supports "CASE ...WHEN..ELSE".
But MS SQL Server does. I'll give u a sample of how it can be done with only SQL Server syantax and how to go around it if u'r using Access.
Please note that I'm just writing on dry run, no testing of my code is done.

Code:
-- MS SQL Server Syantax

declare @attachserial as varchar(50),
            @cname as varchar(50),

set @attachserial='"& Request.QueryString("keyword") &"'
set @cname='"&Request.QueryString("keyword")&"'

select * from warrantyclaims where dname = '("LB_Smith"))' and
case when @attachserial='' then '' else attachserial end like '%'+@attachserial+'%'
and case when @cname='' then '' else cname end like '%'+@cname+'%' 

-- here, the syantax uses 'case' syantax to determine if the variable  
--  is empty or not.
OR

Code:
-- If it is done via other DB like Access ( not sure if it supports the case --syantax anyway)

-- You assign your value to a ASP variable first and then do checking 
-- and see if you need the additional "and statments for u'r SQL Syantax


Rough example
Dim AttachSerial,CName

AttachSerial=Request.QueryString("keyword")
CName=Request.QueryString("keyword")



SQL_Query="select * from warrantyclaims where dname = '("LB_Smith"))'"
if  AttachSerial <>"" then

SQL_Query=SQL_Query + "and attachserial like  "& AttachSerial &"
elseif CName <>"" then
SQL_Query=SQL_Query + "and Cname like  "& CName &"
end if


-- I can't remember if the operator should be "+" or "&&" , you have to check .
All the above are just a rough concept. Hope it helps.
__________________
Patrick Chua
LBMS ( Learn By My Self) NPQ ( No paper Qualification )
Reply With Quote
  #3 (permalink)  
Old 10-09-03, 00:24
cyrus cyrus is offline
Registered User
 
Join Date: Oct 2003
Location: Pune
Posts: 59
Hello,
If ur are doing it in asp then u can do this by using IF else condition
depending on the condition u can get the resultant sql query and then execute it.

Now it depends what u want to build a query.
so u should be very clear when u r dynamically building a query depending on user input

cyrus
Reply With Quote
  #4 (permalink)  
Old 10-09-03, 04:48
Patrick Chua Patrick Chua is offline
Registered User
 
Join Date: Jul 2003
Location: Penang, Malaysia
Posts: 212
err...cyrus, haven't I've given a rough example on what u'r saying already?
__________________
Patrick Chua
LBMS ( Learn By My Self) NPQ ( No paper Qualification )
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On