?
Solved

How do I use two parameters in a SQL Select statement

Posted on 2013-06-21
6
Medium Priority
?
416 Views
Last Modified: 2013-06-21
I created a flat table and I want to pull two different teams out of table I am a little lost cause I'm using this sql select statement

SELECT ID, EmailAddress, ImageUrl, Team, Message, DateX, Upload FROM BaseballMessageLog WHERE (Team = @Team) AND (Team = @Team2) I need two teams for a ASP.NET PAGE. Visual Studio allows you to select the controls that you are going to use as parameters. Any Suggestions
0
Comment
Question by:powerztom
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 3
6 Comments
 
LVL 66

Expert Comment

by:Jim Horn
ID: 39266266
If you need two 'teams' of data in one set, then...

SELECT ID, EmailAddress, ImageUrl, Team, Message, DateX, Upload
FROM BaseballMessageLog
WHERE (Team = @Team) OR (Team = @Team2)  - or WHERE Team IN (@Team, @Team2)

The way you have it coded it's testing the same value to be equal to @team and @team2, and unless those parameters are the same value it would return no rows.
0
 

Author Comment

by:powerztom
ID: 39266373
I am not a Sql Expert but I can move my way through but I got 3  ERROR Messages 1 is the select statement and the other two are when SQL asked for parameters for the teams at first it didn't like the -    in - or WHERE Team IN (@Team, @Team2) then incorrect syntax by WHERE CLAUSE I got screen shots if it helps again I'm not a wizard when it comes to sql.Select query statement Error
Parameters error box

Parameters error boxAny
Of your thoughts would be greatly apprecuiated.Thanks
0
 
LVL 66

Accepted Solution

by:
Jim Horn earned 2000 total points
ID: 39266398
Try just this...

SELECT ID, EmailAddress, ImageUrl, Team, Message, DateX, Upload
FROM BaseballMessageLog
WHERE (Team = @Team) OR (Team = @Team2)  

The dash ( - ) afterwards should have been a double dash ( -- ) so the text to the right was commented out, just to show that there are two ways of doing it.
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

Author Comment

by:powerztom
ID: 39266583
Very Very Nice I was researching but the best way was to hit up you EE Guys you guys are Lifesavers. Thanks
Tom
0
 

Author Closing Comment

by:powerztom
ID: 39266590
Very Nice Work You EE Guys are heroes.Thanks
Tom
0
 
LVL 66

Expert Comment

by:Jim Horn
ID: 39266595
Yeah we're not half bad once we get our gallon of coffee in us.

Thanks for the grade.  Good luck with your project.  -Jim
0

Featured Post

On Demand Webinar: Networking for the Cloud Era

Ready to improve network connectivity? Watch this webinar to learn how SD-WANs and a one-click instant connect tool can boost provisions, deployment, and management of your cloud connection.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

When trying to connect from SSMS v17.x to a SQL Server Integration Services 2016 instance or previous version, you get the error “Connecting to the Integration Services service on the computer failed with the following error: 'The specified service …
This month, Experts Exchange sat down with resident SQL expert, Jim Horn, for an in-depth look into the makings of a successful career in SQL.
Via a live example, show how to extract insert data into a SQL Server database table using the Import/Export option and Bulk Insert.
Via a live example, show how to set up a backup for SQL Server using a Maintenance Plan and how to schedule the job into SQL Server Agent.

649 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question