Solved

How do I use two parameters in a SQL Select statement

Posted on 2013-06-21
6
409 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
  • 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
Master Your Team's Linux and Cloud Stack

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

 

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

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Question has a verified solution.

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

Introduction SQL Server Integration Services can read XML files, that’s known by every BI developer.  (If you didn’t, don’t worry, I’m aiming this article at newcomers as well.) But how far can you go?  When does the XML Source component become …
The article shows the basic steps of integrating an HTML theme template into an ASP.NET MVC project
Using examples as well as descriptions, and references to Books Online, show the documentation available for date manipulation functions and by using a select few of these functions, show how date based data can be manipulated with these functions.
Viewers will learn how to use the SELECT statement in SQL to return specific rows and columns, with various degrees of sorting and limits in place.

770 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