SQL Server Performance Forum – Threads Archive
help with sql joins .. please!!!
I need to populate a drop down list of countries from a sql database. I have the following tables tblCountry tblSeason tblCountrySeasonSample data
tblCountry tblSeason
1 USA ……………1 SPRING
2 MEXICO ……….2 SUMMER
3 ENGLAND ……..3 FALL tblCountrySeason
columns ID SeasonID CountryID
1…..1……1…….aka SPRING USA
2…..2……1…….aka SUMMER USA
3…..2……2…….aka SUMMER MEXICO
4…..1……3…….aka SPRING ENGLAND I want to first have the user select the Season from a drop down list then have a drop down only showing countries that are listed for that season. So if they select Summer it should only show USA and Mexico in the drop down list I know i need to do a join somehow but hopefully someone can help me
Something along these lines should do:
SELECT countryID, country
FROM tblCountry
JOIN tblCountrySeason
ON tblCountry.countryID = tblCountrySeason.CountryID
WHERE tblCountrySeason = @seasonID Assuming this is in a stored procedure and @seasonID is submitted as input paramter from the dropdown box —
Frank Kalis
Moderator
Microsoft SQL Server MVP
Webmaster:http://www.insidesql.de
Little typo there…[<img src=’/community/emoticons/emotion-1.gif’ alt=’

<blockquote id="quote"><font size="1" face="Verdana, Arial, Helvetica" id="quote">quote:<hr height="1" noshade id="quote"><i>Originally posted by DilliGrg</i><br /><br />Little typo there…[<img src=’/community/emoticons/emotion-1.gif’ alt=’


LOL Luis [<img src=’/community/emoticons/emotion-2.gif’ alt=’

of Lately I have became a Fan of Exists Queries.. so here there is another way.. for the same.. SELECT t1.Country,t1.CountryID
FROM tblCountry t1
Where
Exists
(
Select 1 From tblCountrySeason t2 Where t1.CountryID = t2.CountryID And
t1.SeasonID = @@seasonID
) Chirag http://chirikworld.blogspot.com/
Thanks for catching the typo. (<img src=’/community/emoticons/emotion-1.gif’ alt=’

Anyway OP has to learn SQL
http://www.sql-tutorial.net/
http://www.firstsql.com/tutor.htm
http://www.w3schools.com/sql/default.asp
Madhivanan Failing to plan is Planning to fail
thank you for all the help .. SELECT tblCountry.CountryName
FROM tblSeason INNER JOIN
tblCountrySeason ON tblSeason.SeasonID = tblCountrySeason.SeasonID INNER JOIN
tblCountry ON tblCountrySeason.CountryID = tblCountry.CountryID
WHERE (tblSeason.SeasonID = ‘<%Session("Season")%>’) this works in query works but Im trying to set the session("season") from the season drop down and I get the following error Conversion failed when converting the varchar value ‘<%Session("Season")%>’ to data type int. I hoep someone can please help me out thank you
i meant to say this works in query analyzer .. if i put a value "1" but its not working when executed from the code
That’s because of data type precedence. INT has a higher precedence than any string. Try a
WHERE … = CAST( <expression> AS VARCHAR(5)) Sorry, don’t know how to concatenate strings in ASP. In case you’re putting this together dynamically. —
Frank Kalis
Moderator
Microsoft SQL Server MVP
Webmaster:http://www.insidesql.de
<blockquote id="quote"><font size="1" face="Verdana, Arial, Helvetica" id="quote">quote:<hr height="1" noshade id="quote"><i>Originally posted by Luis Martin</i><br /><br /><blockquote id="quote"><font size="1" face="Verdana, Arial, Helvetica" id="quote">quote:<hr height="1" noshade id="quote"><i>Originally posted by DilliGrg</i><br /><br />Little typo there…[<img src=’/community/emoticons/emotion-1.gif’ alt=’



]]>