Click to See Complete Forum and Search --> : creating dynamic query


ruchibutala
October 17th, 2005, 07:50 AM
how do i modify d following query:

select Book_Name,Author,topic,Avilable from Book_Details where Book_Name='" + name +"' and Author='" + author+"' and topic ='" + sub +"'"

d query serches d database
either any of bookname or author or topic or ne 2 or ne 3 could be entered
the where clause should change accordingly

how do i do this???

wildfrog
October 17th, 2005, 08:05 AM
You mean somrething like this?

select Book_Name,Author,topic,Avilable
from Book_Details
where (Book_Name is null or Book_Name='" + name +"') and (Author is null or Author='" + author+"') and (topic is null or topic ='" + sub +"'")

- petter

srinika
October 17th, 2005, 09:14 AM
Ruchibulata,

U want to find the records if either of the fields (book_Name, Author, or Topic) of which searching data is given?

ie. At one stage u want to search the record by book_name, another stage by author, another time by the title - but using the same query?

This is not dynamic!!

Put - OR - instead of - AND -

select Book_Name,Author,topic,Avilable from Book_Details where Book_Name='" + name +"' OR Author='" + author+"' OR topic ='" + sub +"'"