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.

 All Forums
 SQL Server 2000 Forums
 SQL Server Development (2000)
 Passing multiple values for comparison

Author  Topic 

AskSQLTeam
Ask SQLTeam Question

0 Posts

Posted - 2002-03-05 : 08:57:05
Alex writes "Hi Guys,

I'm creating a online work station booking website for my campus.
I need to create a SQL statement to display the stations available for booking for a given date and time provided by the user. Problem is my statement works on single entry of date and time but not for duplicating entries even when the systemnumbers are not the same. i.e. that is different work stations can be booked on the same day and time slot. Below is my table details and my current statement.

System_data
-----------
systemnumber
brand
model
operatingsystem

Booking_data
-------------
systemnumber
memberid
timeslotbooked
datebooked



if (select systemnumber from booking_data where datebooked = '3/2/2002' and timeslotbooked = '1800') is null
begin
select * from system_data order by systemnumber
end
else
begin
select * from system_data where systemnumber <> (select system_data.systemnumber from system_data inner join booking_data on system_data.systemnumber = booking_data.systemnumber where booking_data.datebooked = '3/2/2002' and booking_data.timeslotbooked = '1800') order by system_data.systemnumber
end

Any help please?

Alex"

yakoo
Constraint Violating Yak Guru

312 Posts

Posted - 2002-03-05 : 10:49:28
You probably dont even need to do a check first. Try using a left or right outer join instead of an inner join and return the records that have null values for booking_data.

Something like this

SELECT sd.*
FROM System_data sd
RIGHT OUTER JOIN Booking_data bd
ON sd.Systemnumber = bd.Systemnumber
WHERE bd.Systemnumber is NULL


Go to Top of Page
   

- Advertisement -