Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Code to get table structure
Message
 
To
14/04/2005 10:50:27
General information
Forum:
Visual FoxPro
Category:
Databases,Tables, Views, Indexing and SQL syntax
Environment versions
Visual FoxPro:
VFP 9
OS:
Windows XP SP2
Network:
Windows 2003 Server
Database:
MS SQL Server
Miscellaneous
Thread ID:
01004671
Message ID:
01004690
Views:
25
This message has been marked as a message which has helped to the initial question of the thread.
>Hi,
>
>Does anyone have a function they could share that will provide "SQL create cursor code" if you feed the function with a table/cursor name.
>
>Thanks,

If I understand you corectly you can use AFIELDS() to do this or combile FCOUNT() and FIELDS()
i.e.
FUNCTION ChooseAllFields(ctableName)
 LOCAL ret_val, fl_notused, num_fields, fld_name, i
 ret_val = ""
 IF .NOT. USED(ctableName)
    TRY
       USE (ctableName) IN 0 SHARED && The table is opened in another alias
    CATCH
       USE (ctableName) IN 0 ALIAS TempAlias SHARED && The table is opened in another alias
       ctableName = "TempAlias"
    ENDTRY
    fl_notused = .t.
 ENDIF

 ** 1 way **********************************************
 num_fields = AFIELDS(aFld , ctableName)
 FOR i = 1 TO num_fields
     ret_val = ret_val + IIF(i==1,"",",") + aFld[i,1]
 NEXT
*********************************************************

*** 2 way ***********************************************
 FOR i = 1 TO FCOUNT(ctableName)
     ret_val = ret_val + IIF(i==1,"",",") + FIELDS(i,ctableName)
 NEXT
*********************************************************
 IF fl_notused
    USE IN (ctableName)
 ENDIF

RETURN ret_val


* and you can use it:

c_select = "SELECT "+ChooseAllFields("MyTable") +" FROM MyTable ...."
&c_select
HTH
Against Stupidity the Gods themselves Contend in Vain - Johann Christoph Friedrich von Schiller
The only thing normal about database guys is their tables.
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform