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 Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to make a field in SELECT have necessary size?

Status
Not open for further replies.

Kimed

Programmer
May 25, 2005
104
LT
Hi,

I need an operator like

SELECT field1 AS field,... FROM table1;
UNION ;
SELECT field2 AS field,... FROM table2;
...
INTO CURSOR table_final

The problem is that field1 and field2 (both numeric) have different sizes. As far as I understand, the first processed SELECT will define how fields will look in the final table, but it's not certain that it will actually produce some records, so the next one might be in charge for it. How can I make the resulting field to have a predefined size?

Thanks.
 

For numeric fields, you can try this:

SELECT field1*0000001 AS field1

or

SELECT field1*0000001.0000 AS field1
if you need decimals.

Usually works for me.

For character, you can use PADR() or TRANSFORM() (don't remember, though, if TRANSFORM() was available in earlier versions).

On the other hand, you can always select from table2 first, then order the records the way you need them in the resulting cursor.
 
or create the result table first

==================================== for example
create cursor table_final;
(;
field N(15,3);
)

select field1 as field from table1 into dbf x
sele table_final
appe from x

select field2 as field from table2 into dbf x
sele table_final
appe from x

dele file x.dbf
=======================================
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top