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 |
|
rrb
SQLTeam Poet Laureate
1479 Posts |
Posted - 2002-08-13 : 23:36:43
|
| Hi orlI'm trying to work out a nice, neat, set-based solution (because setbasedisthetruepath after all) to the following:I have a table Bookingsassetid startdate enddate654164 2002-03-30 00:00:00.000 2002-12-26 00:00:00.000654164 2001-01-01 00:00:00.000 2001-01-19 00:00:00.000etcand a table Assetsassetid type active654164 'Yak Head Collar' -1654165 'Yak Head Collar' -1The user makes a request, like they want to borrow 2 Yak Head collars. So far so good.Now here's the tricky bit....On a calendar, I'd like to grey out all the days where there are NOT 2 'Yak Head Collars' available. Now to find out whether a request is possible for a given day is trivial, but how can I return a list of all possible days (say in the current month), without cursoring through each day?suggestions please...PS here's your code for test datacreate table Bookings (assetid int, startdate datetime, enddate datetime)insert into Bookingsselect 654164, CONVERT(datetime, '2002-03-30'), CONVERT(datetime, '2002-12-26')insert into Bookingsselect 654164, CONVERT(datetime, '2001-01-01'), CONVERT(datetime, '2001-01-19')create table assets (assetid int, type nvarchar(50), active int)insert into assetsselect 654164, 'Yak Head Collar', -1 insert into assetsselect 654165, 'Yak Head Collar', -1--I hope that when I die someone will say of me "That guy sure owed me a lot of money"Edited by - rrb on 08/13/2002 23:40:41 |
|
|
nr
SQLTeam MVY
12543 Posts |
Posted - 2002-08-14 : 03:57:14
|
| Probably not the best way but...You will need a temp table of dates #dates - that's easy and been covered beforeselect *from #Dates dwhere ((select count(*) from Assets where type = @type and Active = -1) - (select count(*) from Bookings b, Assets a where b.assetid = a.assetid and a.type = @type and d.date between b.startdate and b.enddate)) >= 2==========================================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. |
 |
|
|
rrb
SQLTeam Poet Laureate
1479 Posts |
Posted - 2002-08-15 : 04:34:42
|
Thanks nigel  --I hope that when I die someone will say of me "That guy sure owed me a lot of money" |
 |
|
|
|
|
|
|
|