Wrox Programmer Forums
|
SQL Server 2000 General discussion of Microsoft SQL Server -- for topics that don't fit in one of the more specific SQL Server forums. version 2000 only. There's a new forum for SQL Server 2005.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the SQL Server 2000 section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old January 26th, 2005, 02:38 PM
Registered User
 
Join Date: Nov 2004
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
Default help

i have two tables one indicates the number of spots to selects depending on a time interval and a channel id.
table allocation

channelid dp1 dp2 dp3 dp4 dp5 dp6 dp7 dp8
8 4 2 2 2 1 1 1 1
9 2 0 2 2 1 1 1 1
19 5 3 3 3 2 2 2 2


table grid

gridid channelid bdate btime btype
.... 8 16200 720 soft
.... 8 16200 720 soft
.... 8 16200 1080 int

and so on

by the way dp1 : 0<= btime <21600
dp2 : 21600<= btime < 32400
dp3 : 32400<= btime < 43200
dp4 : 43200<= btime < 57600
dp5 : 57600<= btime < 68400

what i need to do is
1, select btype, gridids where btype is 'soft' and if btime falls into dp1, select dp1 many gridids,
if btime falls into dp2 select dp2 many gridids and they cannot follow each other.
for that i thought i could use
gridid % 5 = 0.

i couldnt put it all together

any idea on how to do this?

 
Old March 3rd, 2005, 12:29 AM
Authorized User
 
Join Date: Feb 2005
Posts: 30
Thanks: 0
Thanked 0 Times in 0 Posts
Default

It seems conditions mentioned are wrong shouldn;t be like this
dp1 : 0>= btime <21600
dp2 : 21600>= btime < 32400
dp3 : 32400>= btime < 43200
dp4 : 43200>= btime < 57600
dp5 : 57600>= btime < 68400

Query can be like this to get the required results:
SELECT GridId,
        ChannelId,
        (CASE WHEN g.bTime>=0 AND g.bTime<21600 THEN DP1
            WHEN g.bTime>=21600 AND g.bTime<32400 THEN DP2
            WHEN g.bTime>=32400 AND g.bTime<43200 THEN DP2
            WHEN g.bTime>=43200 AND g.bTime<57600 THEN DP2
            WHEN g.bTime>=57600 AND g.bTime<68400 THEN DP2
        END) as NoOfSpots
FROM Grid g, Allocation a
WHERE g.channelid=a.channelid
g.bType='soft'

Cheers,
Pooja Falor









Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.