Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2000 Forums
 Transact-SQL (2000)
 sql query via parameters

Author  Topic 

ashwika
Starting Member

9 Posts

Posted - 2011-03-16 : 19:28:51
I have a file with Request details and another table with Booking Details

Request table
Key – requested
managerID
dateRequested
noPcsReq
noPcsBooked
loanFrom
requestDate


Booking Table
Key : bookingID
requestID
managerID
dateRequested
dateLoanFrom
dateReturned
noPcsBooked


Manager table
Key managerID
name
telephone

a user is allowed to query the database to find all records relating to

a) Manager or
b) Manager and fromRequestDate and ToRequestDate

And output results containing:

No.of pcs ordered ,
noPcsBooked
date requested
Loanfrom date
Manager
etc etc


So 3 parameters @managerID and @fromDate and @toDate will be input
to this query .
How do I query the tables in SQL – please advise

ms65g
Constraint Violating Yak Guru

497 Posts

Posted - 2011-04-08 : 13:56:04
Your request is dynamic searching.
Try something like this:


SELECT any_columns_you_need
FROM Request
Natural Join Booking
Natural Join Manager
WHERE (manager_name = @manager_name OR @manager_name IS NULL)
AND (fromRequestDate = @param OR @param IS NULL)
AND ...




______________________
Go to Top of Page

Lamprey
Master Smack Fu Yak Hacker

4614 Posts

Posted - 2011-04-08 : 14:31:06
For reference:
http://sqlinthewild.co.za/index.php/2009/03/19/catch-all-queries/
Go to Top of Page
   

- Advertisement -