Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Counting Strings in a Field
Message
From
05/03/2009 12:24:13
John White
Micro-Oriented Software Techniques, Inc.
Phoenix, Arizona, United States
 
General information
Forum:
Visual FoxPro
Category:
Databases,Tables, Views, Indexing and SQL syntax
Environment versions
Visual FoxPro:
VFP 9 SP1
OS:
Windows XP SP2
Network:
Windows 2008 Server
Database:
Visual FoxPro
Application:
Desktop
Miscellaneous
Thread ID:
01385278
Message ID:
01385887
Views:
31
>>>I have a table with a field that contains one or more strings separtated by commas. I need a SPT that can count the number of strings. The table is a db2 file.
>>
>>Maybe I'm missing something but wouldn't this work:
>>
>>
>>Select PK, iif(empty(myfield),0,occurs(',',myfield)+1) as stringcnt from mytable group by 1 into cursor mycursor
>>calculate sum(stringcnt) to totalcnt
>>
>>
>>to get the number of strings in each record and a total count for the file. Of course, if all you need is a total count for the file:
>>
>>
>>Select SUM(iif(empty(myfield),0,occurs(',',myfield)+1)) as stringcnt from mytable into cursor mycursor
>>
>
>Except for the fact that there is no native OCCURS function in SQL Server and I'm not sure about DB2.

That would be what I was missing... TSQL vs Fox syntax.
John White [MOST]
Previous
Reply
Map
View

Click here to load this message in the networking platform