Click here to monitor SSC
SQLServerCentral is supported by Red Gate Software Ltd.
 
Log in  ::  Register  ::  Not logged in
 
 
 
        
Home       Members    Calendar    Who's On


Add to briefcase

Enquiry on retrieving data from database Expand / Collapse
Author
Message
Posted Friday, July 18, 2014 11:58 AM
Forum Newbie

Forum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum Newbie

Group: General Forum Members
Last Login: Friday, July 18, 2014 1:46 PM
Points: 1, Visits: 7
Hi,

I have a drop down menu for transmission. Inside the drop down menu, there are 1.Any 2.Auto 3.Manual options

Now I want to retrieve from my database, if the client select '1.Any' option. Meaning the output I want it to display all the products which have both auto and manual for transmission.

I am not sure what is the coding should be like. Can any one help me out with this.
I have no problem retrieving all the products which either only have auto option or manual option.

Your help is greatly appreciated. Thank you very much.
Post #1594184
Posted Friday, July 18, 2014 12:25 PM
Hall of Fame

Hall of FameHall of FameHall of FameHall of FameHall of FameHall of FameHall of FameHall of FameHall of Fame

Group: General Forum Members
Last Login: Today @ 10:51 AM
Points: 3,998, Visits: 3,433
Hello and welcome to the forums.

If they select Any, you don't want to apply the WHERE clause. If another one is selected, you want to apply the WHERE clause. Since I don't know what your table looks like, here's a general approach. It's probably much simpler than what you're after, but it's the approach that counts:

--create a table to hold the parts where TransmissionID denotes the type
create table #parts (
ID Integer not null identity (1, 1),
Description varchar(32),
TransmissionID Integer);

--depending on @TransmissionID passed to the procedure, query the parts list
IF @TransmissionID IS NULL
BEGIN
SELECT ID, Description
FROM #parts
ORDER BY Description;
END;
ELSE
BEGIN
SELECT ID, Description
FROM #parts
WHERE TransmissionID = @TransmissionID
ORDER BY Description;
END;

HTH



Tally Tables - Performance Personified
String Splitting with True Performance
Best practices on how to ask questions
Post #1594193
Posted Friday, July 18, 2014 12:30 PM


SSChampion

SSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampion

Group: General Forum Members
Last Login: Today @ 11:21 AM
Points: 10,196, Visits: 13,126
You haven't told us what you are using for querying the database? Are you using SSRS, .NET, java? What are you using for database access, ad hoc SQL, an ORM tool (Entity Framework, nHibernate, Hibernate), or stored procedures?

So even without the answer to those questions here's a generic answer to your original post. At some point you need to interrogate the choice that was made and if it is "Any" don't add a where clause to your query. So in pseudo code it would be something like this:

If Parameter Value = "Any" THEN
query = Select columns from table
Else
query = Select columns from table where transmission = parameter.value




Jack Corbett

Applications Developer

Don't let the good be the enemy of the best. -- Paul Fleming

Check out these links on how to get faster and more accurate answers:
Forum Etiquette: How to post data/code on a forum to get the best help
Need an Answer? Actually, No ... You Need a Question
How to Post Performance Problems
Crosstabs and Pivots or How to turn rows into columns Part 1
Crosstabs and Pivots or How to turn rows into columns Part 2
Post #1594196
« Prev Topic | Next Topic »

Add to briefcase

Permissions Expand / Collapse