Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Create an Integer field on the fly
Message
Information générale
Forum:
Visual FoxPro
Catégorie:
Base de données, Tables, Vues, Index et syntaxe SQL
Divers
Thread ID:
00382290
Message ID:
00382359
Vues:
17
>>>>>>Hi everyone,
>>>>>>
>>>>>>I'd like to create an Integer field in a select statement. AFAIK, by default it creates Numeric field. How can I do this?
>>>>>>E.g.
>>>>>> Select space(1) as moditype, ctot('') as PostTime, ? as Error (should be Integer field), .f. as Posted, etc.
>>>>>>
>>>>>>Thanks in advance.
>>>>>
>>>>>sele 000 as intfield && creates three digit integer field
>>>>
>>>>It creates Numeric field, not Integer!!!!!!
>>>
>>>I know that numeric works in your current context, but in case you ever want to create an integer constant on the fly the following works:
>>>
>>>Than do an inner join on a expression that will always evaluate to .t. (for example 1=1). Voila -- you can now put the constant of the right type and value into every row in your result example:
>>>
>>>
>>>CREATE TABLE henig (f1 c(10))
>>>APPEND BLANK
>>>REPL f1 WITH "x"
>>>APPEND BLANK
>>>REPL f1 WITH "y"
>>>APPEND BLANK
>>>REPL f1 WITH "z"
>>>
>>>
>>>CREATE CURSOR henig2 (f2 i)
>>>APPEND BLANK
>>>REPL f2 WITH 22
>>>
>>>
>>>SELECT henig.f1,henig2.f2 FROM henig inner JOIN henig2 ON 1=1
>>>
>>>
>>>
>>>Do a display stru on Query, and you will see that f2 not only has a value of 22 but is an integer type. This also works to let you create null constants of any data type you want. If you work with large files, this is a lot faster than adding an "append from" to your code.
>>
>>Hi Gar,
>>
>>You really confuses me :) In your example henig2.f2 already has an Integer data type. Change it to be Numeric and see, if it works. And I need to create additional fields (not in database) with predefined type:
>>1 Logical field,
>>2 Character fields
>>2 DataTime fields (I use ctot(''))
>>One integer field.
>>I guess, transform can help me here, but since it's not a problem anymore, I haven't investigated it.
>
>
>
>Basically what I am saying here is:
>1) Certain data types (integer, any type field with null) are impossible to create directly in a select statement.
>2)But you can create a cursor on the fly that contains a field of the right type. Do a join onto this cursor and you get get fields of the type you could otherwise select.

Very cool tip I will definetly remeber this one. Thanks.
Rip Ryness
International Falls, MN
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform