Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Query Question
Message
 
 
À
29/04/2009 18:13:36
James Blackburn
Qualty Design Systems, Inc.
Kuna, Idaho, États-Unis
Information générale
Forum:
Visual FoxPro
Catégorie:
Client/serveur
Titre:
Versions des environnements
Visual FoxPro:
VFP 9 SP1
OS:
Windows XP SP2
Divers
Thread ID:
01397059
Message ID:
01397168
Vues:
93
This message has been marked as a message which has helped to the initial question of the thread.
This is SQL Server solution from limno, who is SQL genious:
DECLARE @t TABLE (booknumber int, Ticketbook int, status char(1)) 
 INSERT INTO @t SELECT 1, 1,'Y'
UNION ALL SELECT 1,2, 'Y'  
UNION ALL SELECT 1,4, 'Y' 
UNION ALL SELECT 1,5, 'N'  
 UNION ALL SELECT 1,6, 'N'  
  UNION ALL SELECT 1,7, 'N'  
 UNION ALL SELECT 1,9, 'N' 
UNION ALL SELECT 1,10, 'Y'   
 UNION ALL SELECT 1,11, 'Y' 
UNION ALL SELECT 1,12, 'Y' 
UNION ALL SELECT 1,13, 'N' 
UNION ALL SELECT 1,3, 'Y' 
 UNION ALL SELECT 1,14, 'N'  
UNION ALL SELECT 1,15, 'N'  
UNION ALL SELECT 1,16, 'N'  
UNION ALL SELECT 1,17, 'N' 
 UNION ALL SELECT 1,18, 'N' 
UNION ALL SELECT 1,8, 'N'  
UNION ALL SELECT 1,19, 'N'  
UNION ALL SELECT 1,21, 'N'  
 UNION ALL SELECT 1,22, 'N'  
UNION ALL SELECT 1,23, 'N'  
UNION ALL SELECT 1,24, 'N'  
UNION ALL SELECT 1,25, 'N' 
 UNION ALL SELECT 1,20, 'N' 
 
 SELECT booknumber, Ticketbook, status , null as gid INTO ##T FROM @t ORDER BY Ticketbook
 DECLARE @i int 
 SET @i=0
 UPDATE a
 SET    @i= CASE WHEN a.Status<>b.status THEN @i+1 ELSE @i END,
 gid=  @i FROM ##T a LEFT JOIN ##T b On b.Ticketbook=a.Ticketbook-1
 
 --SELECT booknumber, MIN(Ticketbook) as minTicketbook--, MAX(Ticketbook) as maxTicketbook FROM ##T--GROUP BY booknumber, status
 SELECT booknumber, status, MIN(Ticketbook) as minTicketbook, MAX(Ticketbook) as maxTicketbook FROM ##T
 GROUP BY booknumber,gid, status
 ORDER BY booknumber, gid, status
 
 DROP TABLE ##T
The link to the thread is http://forums.asp.net/p/1417268/3129677.aspx#3129677 .
Still his solution uses a temporary table/cursor.

>Thanks Naomi. You can post on another place is you want. I am going to post on the Sybase board. I will let you know what the say.
>
>>>That gave me the same results as the example I started with. I need to group by some type of sequence number when the status changes??
>>>
>>
>>It should not have given you the exact same result. Post the exact result from the query I gave you.
>>
>>I was thinking a bit more on the problem, this seems to be running total kind of query. I can post you some links on running total and you can see if you can proceed from there.
>>
>>I also plan to ask this question on another board (if this is Ok with you) because I found this problem quite interesting.
>>
>>>>>I have a query that I can't figure out. I need to list log delivery tickets (truck loads of trees) based on the number of tickets in a book and the min and max of the tickets that have been used and not used. Sounds simple so far. The problem is when the tickets are used out of order in the book. In a book of 25 tickets, if tickets 1,2,3,4 has been used, 5,6,7,8,9 has not been used, and 10,11,12 have been used, then I need the following list.
>>>>>
>>>>>Ticket book status    Min ticket   Max ticket
>>>>>    1               Y        1                4
>>>>>    1               N        5                9
>>>>>    1               Y       10              12
>>>>>    1               N       13              25             
>>>>>
>>>>>The query has the following list.
>>>>>
>>>>>select booknumber,status, min(ticket),max(ticket) from tickets
>>>>>group by booknumber,status
>>>>>
>>>>>Ticket book status    Min ticket   Max ticket
>>>>>    1               Y        1                12
>>>>>    1               N        5                25
>>>>>
>>>>>
>>>>>Any way to do this in a query?
>>>>>
>>>>>Thanks.
>>>>
>>>>Complex problem. I tried to think of a SQL solution and I guess you would need self-join of something like
>>>>
>>>>select T1.*, T2.* from Tickets T1 left Join Tickets T2 on T1.Book = T2.Book  and  T1.Status = T2.Status and T1.Ticket < T2.Ticket 
>>>>
>>>>See what results you get by this and if you can somehow proceed from it. If not, I would use procedural code - it seems pretty straightforward.
If it's not broken, fix it until it is.


My Blog
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform