SQL Clone
SQLServerCentral is supported by Redgate
 
Log in  ::  Register  ::  Not logged in
 
 
 


Enquiry on retrieving data from database


Enquiry on retrieving data from database

Author
Message
mysterious_qi
mysterious_qi
Forum Newbie
Forum Newbie (1 reputation)Forum Newbie (1 reputation)Forum Newbie (1 reputation)Forum Newbie (1 reputation)Forum Newbie (1 reputation)Forum Newbie (1 reputation)Forum Newbie (1 reputation)Forum Newbie (1 reputation)

Group: General Forum Members
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.
Ed Wagner
Ed Wagner
SSC Guru
SSC Guru (50K reputation)SSC Guru (50K reputation)SSC Guru (50K reputation)SSC Guru (50K reputation)SSC Guru (50K reputation)SSC Guru (50K reputation)SSC Guru (50K reputation)SSC Guru (50K reputation)

Group: General Forum Members
Points: 50223 Visits: 10844
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
Jack Corbett
  Jack Corbett
SSC-Forever
SSC-Forever (45K reputation)SSC-Forever (45K reputation)SSC-Forever (45K reputation)SSC-Forever (45K reputation)SSC-Forever (45K reputation)SSC-Forever (45K reputation)SSC-Forever (45K reputation)SSC-Forever (45K reputation)

Group: General Forum Members
Points: 45453 Visits: 14925
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
At best you can say that one job may be more secure than another, but total job security is an illusion. -- Rod at work

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
Go


Permissions

You can't post new topics.
You can't post topic replies.
You can't post new polls.
You can't post replies to polls.
You can't edit your own topics.
You can't delete your own topics.
You can't edit other topics.
You can't delete other topics.
You can't edit your own posts.
You can't edit other posts.
You can't delete your own posts.
You can't delete other posts.
You can't post events.
You can't edit your own events.
You can't edit other events.
You can't delete your own events.
You can't delete other events.
You can't send private messages.
You can't send emails.
You can read topics.
You can't vote in polls.
You can't upload attachments.
You can download attachments.
You can't post HTML code.
You can't edit HTML code.
You can't post IFCode.
You can't post JavaScript.
You can post emoticons.
You can't post or upload images.

Select a forum

































































































































































SQLServerCentral


Search