Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Query Question
Message
From
30/04/2009 13:50:25
James Blackburn
Qualty Design Systems, Inc.
Kuna, Idaho, United States
 
General information
Forum:
Visual FoxPro
Category:
Client/server
Title:
Environment versions
Visual FoxPro:
VFP 9 SP1
OS:
Windows XP SP2
Miscellaneous
Thread ID:
01397059
Message ID:
01397268
Views:
55
Brandid holds ticket books. Give brandid the value of 1 and it will work.

>BTW, somehow I'm not getting the result - probably because of the wrong data sample?
>
>DECLARE @t TABLE (brandid int identity, bookgroup int, Ticket 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  aa.brandid,aa.bookgroup,aa.ticket,aa.status,
>  sum(CASE WHEN aa.Status<>b.status THEN 1 ELSE 0 END) as seq
>into #tktmp 
>FROM @t as aa 
>LEFT JOIN @t as b 
>On b.Ticket>aa.Ticket and b.bookgroup = aa.bookgroup 
>group by  aa.brandid,aa.bookgroup,aa.ticket,aa.status
>order by aa.bookgroup,aa.ticket 
>
>select brandid,bookgroup,seq,status, min(ticket) as mintick, max(ticket) as maxtick
>from #tktmp 
>group by brandid,bookgroup,seq,status
>order by brandid, bookgroup,mintick 
>DROP TABLE #Tktmp
>
>
>>Yes I did. Sometimes it takes a while to get my head wrapped around a concept.
>>Thanks again.
>>
>>>Your solution seems to be much easier. BTW, you did use my original suggestion of self-join :)
>>>
>>>>I got it to work this way. Thanks for your help.
>>>>
>>>>
>>>>select  aa.brandid,aa.bookgroup,aa.ticket,aa.status,
>>>>  sum(CASE WHEN aa.Status<>b.status THEN 1 ELSE 0 END) as seq
>>>>into #tktmp 
>>>>FROM tickets as aa 
>>>>LEFT JOIN tickets as b 
>>>>On b.Ticket>aa.Ticket and b.bookgroup = aa.bookgroup 
>>>>group by  aa.brandid,aa.bookgroup,aa.ticket,aa.status
>>>>order by aa.bookgroup,aa.ticket 
>>>>
>>>>select brandid,bookgroup,seq,status,min(ticket) as mintick, max(ticket) as maxtick
>>>>from #tktmp 
>>>>group by brandid,bookgroup,seq,status
>>>>order by bookgroup,mintick 
>>>>
>>>>
>>>>
>>>>>>Sql Anywhere does use temp tables and cursors. I have always avoided cursors because they tend to be slow. My problem is with the @i counter. Sql Anywhere does not like it.
>>>>>>
>>>>>>Thanks.
>>>>>>
>>>>>
>>>>>May be it's SQL Server only feature to be able to use such update. I haven't tried this code in VFP, didn't have time.
>>>>>
>>>>>Brandon, can you try it in VFP, please?
>>>>>
>>>>>>>>Thanks Naomi,
>>>>>>>>
>>>>>>>>I am having a some trouble adapting the syntax to Sql Anywhere but it gave me some ideas.
>>>>>>>>
>>>>>>>You're welcome. Does Sql Anywhere have temp tables concept / cursors? There was another solution in the mentioned thread using CURSORS, but I think temp table solution with this interesting UPDATE is much better.
Previous
Reply
Map
View

Click here to load this message in the networking platform