Please start any new threads on our new
site at https://forums.sqlteam.com. We've got lots of great SQL Server
experts to answer whatever question you can come up with.
Author |
Topic |
Johnny1985
Starting Member
26 Posts |
Posted - 2008-04-13 : 08:49:02
|
I have two tables:1) Table that holds all available ports.2) Table that holds users for each port.There may be times where one user is getting more than one port at a time.I've built up an ASP .NET page that will display each user its port/s in one table.On another table I want to display all the other available ports which the user doesn't posses and can buy to own.My problem is where I try to build up the query. I just can't get all the other ports in normal display.For example, this is what I need:Ports table:1/11/21/31/4Users table:User A , 1/1User A , 1/2ASP page display:------------User A Holds:1/11/2------------Available:1/31/4------------Of course the Available option is derived from the User Holds query, and just getting the opposit not equal ports, but I just can't get it !I've tried all kinds of Joins and nesting SELECT queries with no luck.I hate SQL. I want to die. |
|
nr
SQLTeam MVY
12543 Posts |
Posted - 2008-04-13 : 09:34:48
|
select p.port, u.userfrom ports pleft join users son p.port = u.portwill give all portsto give available portswhere u.user is nullto give used portswhere u.user is not null==========================================Cursors are useful if you don't know sql.DTS can be used in a similar way.Beer is not cold and it isn't fizzy. |
 |
|
Johnny1985
Starting Member
26 Posts |
Posted - 2008-04-13 : 10:46:42
|
Hey man, thanks for the quick reply !!I've tried what you suggested, and I get the same results from my queries.It seems that I get results pane for every port, that is:If I have 1/1 and 1/2 used by the user, then I should be getting 1/3 and 1/4 as results.What I'm actually getting is:1/2, 1/3, 1/4 , 1/1, 1/3, 1/4Any idea why this is happening ? |
 |
|
nr
SQLTeam MVY
12543 Posts |
Posted - 2008-04-13 : 11:24:40
|
did you read the last bit?For that you need to add the whare clausewhere u.user is nullOr test for it in the app.==========================================Cursors are useful if you don't know sql.DTS can be used in a similar way.Beer is not cold and it isn't fizzy. |
 |
|
Johnny1985
Starting Member
26 Posts |
Posted - 2008-04-13 : 12:13:00
|
I stupidly putted equal to NULL instead of IS NULL.Thanks a lot ! You don't know how much you've helped !! |
 |
|
|
|
|
|
|