Solved

How do I use two parameters in a SQL Select statement

Posted on 2013-06-21
6
412 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 65

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 65

Accepted Solution

by:
Jim Horn earned 500 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
Best Practices: Disaster Recovery Testing

Besides backup, any IT division should have a disaster recovery plan. You will find a few tips below relating to the development of such a plan and to what issues one should pay special attention in the course of backup planning.

 

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 65

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

Comparison of Amazon Drive, Google Drive, OneDrive

What is Best for Backup: Amazon Drive, Google Drive or MS OneDrive? In this free whitepaper we look at their performance, pricing, and platform availability to help you decide which cloud drive is right for your situation. Download and read the results of our testing for free!

Question has a verified solution.

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

I have a large data set and a SSIS package. How can I load this file in multi threading?
Recently we ran in to an issue while running some SQL jobs where we were trying to process the cubes.  We got an error saying failure stating 'NT SERVICE\SQLSERVERAGENT does not have access to Analysis Services. So this is a way to automate that wit…
Via a live example, show how to setup several different housekeeping processes for a SQL Server.
Viewers will learn how the fundamental information of how to create a table.

734 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