Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

SQL-select specific field types?!?!?!?

Status
Not open for further replies.

DanEvansJr

Programmer
Aug 17, 2001
41
US
Is there a quick and dirty way to select fields from a table that only match a specific type??

EX: Only yanking numeric fields.

I know you can store the field types to an array, then use that array to determine field names, then use those names to build an sql statement, but is there a quicker way to do this????
 
If you know which fields are of a given type (table documentation!), then you could use the field selector in the Query Builder to select them. Then you could cut the field list from the View SQL window and paste it in your program.

Rick
 
You could do something like this:

VarTable="secure"
sqlcmd=""
USE &VarTable
FOR x = 1 TO AFIELDS(TempArray)
IF TYPE(TempArray(X,1))="N"=.t.
sqlcmd=ALLTRIM(sqlcmd)+"sum("+TempArray(X,1)+"),"
ENDIF
ENDFOR
sqlcmd="sele "+ALLTRIM(LEFT(sqlcmd,LEN(sqlcmd)-1))+" from "+vartable+ " into table SQLResult"
&sqlcmd
 
Or if you use:
sqlcmd=ALLTRIM(sqlcmd)+" "+TempArray(X,1)+","

you will get only the numeric fields in the table on a record level as your results...

Brian
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top