Solved

How do I use two parameters in a SQL Select statement

Posted on 2013-06-21
6
408 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
Optimizing Cloud Backup for Low Bandwidth

With cloud storage prices going down a growing number of SMBs start to use it for backup storage. Unfortunately, business data volume rarely fits the average Internet speed. This article provides an overview of main Internet speed challenges and reveals backup best practices.

 

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

Let's review the features of new SQL Server 2012 (Denali CTP3). It listed as below: PERCENT_RANK(): PERCENT_RANK() function will returns the percentage value of rank of the values among its group. PERCENT_RANK() function value always in be…
For both online and offline retail, the cross-channel business is the most recent pattern in the B2C trade space.
Familiarize people with the process of utilizing SQL Server functions from within Microsoft Access. Microsoft Access is a very powerful client/server development tool. One of the SQL Server objects that you can interact with from within Microsoft Ac…
Via a live example, show how to setup several different housekeeping processes for a SQL Server.

911 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

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now