Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Code to get table structure
Message
From
14/04/2005 11:18:03
 
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:
01004692
Views:
21
Thanks Guys!

Best,

>>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
-=Gary
Previous
Reply
Map
View

Click here to load this message in the networking platform