Free Scan: Update Your PC's Outdated Drivers to Optimize Performance
October 1st, 2008, 01:41 PM
|
#1 (permalink)
| | Junior Member
Join Date: Oct 2008
Posts: 8
| vbscript and SQL versus joins
I have a database - with two tables, one which contains different countries and one containing user names and their choices - they are connected (relational) via a field called country number.
Now i want to make a selection showing which contries a user has picked - meaning which contries from the "available" table, has a certain user NOT selected. - this is my code but it doesnt work.
' VB
sub main()
Dim Portal
Dim Query
Dim uRS
Dim uSQL
'Connect to DB
'*************
Set uConn = server.CreateObject("ADODB.Connection")
uConn.Open Application("countrystr")
uSQL = "SELECT DISTINCT CountryCode, Name, User, CountrySelected FROM Contries FULL OUTER JOIN Selected ON countries.CountryCode <> Selected.CountrySelected WHERE User = 'Tom' AND countries.CountryCode <> Selected.CountrySelected ORDER BY CountryCode"
Set uRS = uConn.Execute(uSQL)
Do While not uRS.EOF
Content.Add(uRS("CountryCode") & " - " & uRS("Name") & &"</a><BR />")
uRS.MoveNext
Loop
Set uRS = Nothing
uConn.Close
end sub |
| |
October 1st, 2008, 02:09 PM
|
#2 (permalink)
| | Ultimate Member
Join Date: Oct 2001
Posts: 20,457
|
I dont believe you can use a join with <>
Wouldn't make much sense
The FULL OUTER JOIN should fulfill that purpose |
| |
October 1st, 2008, 03:04 PM
|
#3 (permalink)
| | Junior Member
Join Date: Oct 2008
Posts: 8
|
So what you mean is
uSQL = "SELECT DISTINCT CountryCode, Name, User, CountrySelected FROM Contries FULL OUTER JOIN Selected ON countries.CountryCode = Selected.CountrySelected WHERE User = 'Tom' AND countries.CountryCode <> Selected.CountrySelected ORDER BY CountryCode" |
| |
October 1st, 2008, 03:22 PM
|
#4 (permalink)
| | Junior Member
Join Date: Oct 2008
Posts: 8
|
It doesn't work - it gives all contries that the user has selected, I want those from the first table, that the user did not select |
| |
October 1st, 2008, 03:23 PM
|
#5 (permalink)
| | Junior Member
Join Date: Oct 2008
Posts: 8
|
uSQL = "SELECT DISTINCT CountryCode, Name, User, CountrySelected FROM Contries FULL OUTER JOIN Selected ON countries.CountryCode <> Selected.CountrySelected WHERE User = 'Tom' ORDER BY CountryCode"
Doesn't work either - same result |
| |
October 1st, 2008, 03:56 PM
|
#6 (permalink)
| | Ultimate Member
Join Date: Oct 2001
Posts: 20,457
|
OH then you need a left or right outer join, not full
try LEFT, see if you get the correct results.. if that doesn't work try RIGHT |
| |
October 1st, 2008, 04:18 PM
|
#7 (permalink)
| | Junior Member
Join Date: Oct 2008
Posts: 8
|
I did try both, both either works |
| |
October 1st, 2008, 11:42 PM
|
#8 (permalink)
| | Ultimate Member
Join Date: Oct 2001
Posts: 20,457
|
tell me this thing is a typo? Code: uSQL = "SELECT DISTINCT CountryCode, Name, User, CountrySelected FROM Contries FULL OUTER JOIN Selected ON countries.CountryCode <> Selected.CountrySelected WHERE User = 'Tom' AND countries.CountryCode <> Selected.CountrySelected ORDER BY CountryCode" you're linking contries instead of countries  |
| |
October 2nd, 2008, 03:37 AM
|
#9 (permalink)
| | Junior Member
Join Date: Oct 2008
Posts: 8
|
its a typo - Im actually getting output - either all records from Selected or all records in Selected where User = "ULS" or nothing.
I Want it to show all records from Countries, that ULS did not select |
| |
October 2nd, 2008, 04:09 AM
|
#10 (permalink)
| | Junior Member
Join Date: Oct 2008
Posts: 8
|
I have solved it - yes yes |
| | |
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | | |
Posting Rules
| You may post new threads You may post replies You may not post attachments You may not edit your posts HTML code is Off | | | | Most Active Discussions | | | | | Recent Discussions  | | | | | |