Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
SQL Horizontal Count
Message
From
18/09/2001 13:59:26
Keith Payne
Technical Marketing Solutions
Florida, United States
 
General information
Forum:
Visual FoxPro
Category:
Databases,Tables, Views, Indexing and SQL syntax
Miscellaneous
Thread ID:
00557820
Message ID:
00558013
Views:
19
>Having a brain cramp.
>
>I have a table consisting of:
>
>person_id - char(10)
>flag_1 - logical
>flag_2 - logical
>flag_3 - logical
>
>
>I want to do a SQL statment which returns the person_id for any person who has more than 1 of any of the flag fields set to TRUE.
>
>
>select person_id from mytable where flag_1 OR flag_2 OR flag_3 ...but more than one of them....!
>
>
>
>any ideas? Thanks - Larry
local lnFieldCount, i, lcColumnList
local array laFields[1,16]

use mytable in 0

lnFieldCount = afields(laFields, 'mytable')

lcColumnList = ''
for i = 1 to lnFieldCount
     if laFields[i,2] = 'L'
          lcColumnList = lcColumnList + 'iif('+laFields[i,1]+',1,0)+'
     endif
endfor

if len(lcColumnList) > 1
     lcColumnList = left(lcColumnList,len(lcColumnList)-1)+' as flag_total'
     
     select person_id, &lcColumnList ;
     from mytable
     where flag_total > 1
else
     select person_id
     from mytable
     where .F.
endif
Previous
Reply
Map
View

Click here to load this message in the networking platform