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

How to add column

Status
Not open for further replies.

alisaif

ISP
Apr 6, 2013
418
AE
Hi,

I want to add field in cursor like the following:

myr = '2011'
myr1 = '2012'
myr1 = '2013'
myr1 = '2014'
myr1 = '2015'
myr1 = '2016'

SELECT YEAR(invdate) as theyear,;
location As location, ;
sum(qntymaj) As cartons, ;
sum(qntymin) As units, ;
sum(Iif(ratemin#0,qntymin*ratemin,qntymaj*ratemaj)) As mamount ;
from SalQuery ;
group By theyear,location ;
INTO CURSOR tempsi READWRITE
ALTER table tempsi ADD COLUMN &mYr n(13,2)
ALTER table tempsi ADD COLUMN &mYr1 n(13,2)
ALTER table tempsi ADD COLUMN &mYr2 n(13,2)
ALTER table tempsi ADD COLUMN &mYr3 n(13,2)
ALTER table tempsi ADD COLUMN &mYr4 n(13,2)
ALTER table tempsi ADD COLUMN &mYr5 n(13,2)

I want to general the header like 2011,2012,2013,2014,2015,2016 instead of myr,myr1,myr2,myr3,myr4,myr5,myr6.

It gives syntax error. Please let me know what is wrong in this?

Thanks

Saif
 
Names can't be digits only. Start of a name must either be underscore or letter.
You have to use a header caption differing from field name to get just the year number as caption.

Bye, Olaf.
 
Thanks Olaf,

I did like this but still get errors"

myr = 'Y-'+mYear &&Y-2016
myr1 = 'Y-'+ALLTRIM(STR(mYear1)) &&Y-2015
myr2 = 'Y-'+ALLTRIM(STR(mYear2)) &&Y-2014
myr3 = 'Y-'+ALLTRIM(STR(mYear3)) &&Y-2013
myr4 = 'Y-'+ALLTRIM(STR(mYear4)) &&Y-2012
myr5 = 'Y-'+ALLTRIM(STR(mYear5)) &&Y-2011

Please suggest

Thanks

Saif
 
Saif,

You now have a hyphen in your column names. Hyphens are not permitted. Use an underscore instead.

In other words, instead of:

[tt]Y-2015[/tt]

you should have

[tt]Y_2015[/tt]

or alternatively simply

Y2015

Mike

__________________________________
Mike Lewis (Edinburgh, Scotland)

Visual FoxPro articles, tips and downloads
 
Thanks Mike, it done!!!

Thanks Mr.Olaf too

Saif
 
Hyphen makes up an expression with minus. Anyway, solved.

Bye, Olaf.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top