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
 SQL Server Development (2000)
 Build dynamic SQL string query

Author  Topic 

AskSQLTeam
Ask SQLTeam Question

0 Posts

Posted - 2001-11-18 : 11:11:44
Steve writes "Hi -

I have a search facility on my ASP (SQL Server2000) site using the following drop-down selection criteria:

1)Project Name
<option selected value="all">All
projectsids

2)Country
<option selected value="all">All
countryids

3)Project Type
<option selected value="all">All
projecttypeids

4)Project Owner Name
<option selected value="all">All
ownerids

Start Date
(date drop-down)

End Date
(date drop-down)

I have a SQL query linking the following tables like this:
select project.projectid, project.projectname, project.startdate, project.enddate, projecttype.projecttypename, country.countryname, engineers.engineerfirstname, engineers.engineersurname from project inner join projecttype on project.projecttypeid = projecttype.projecttypeid inner join country on project.countryid = country.countryid inner join engineers on project.engineerid = engineers.engineerid where " & searchstr & "

Depending on what is selected the searchstr finishes the query.

The problem is that there are many permutations where the default value rules out that part of the query.

How can I dynamically build the query without too many lines of code?

I'm also paging the results - limiting the page to 5 results with links built dynamically, which I've done. But, I also need to pass the initial query with the page links to the same page.

Please can you help as this is doing my head in.

Many thanks in advance.

Cheers,
Steve"
   

- Advertisement -