Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Select sql result
Message
De
26/05/2011 07:10:05
Mk Sharma
Shrishti Solutions
Mumbai, Inde
 
 
À
25/05/2011 15:41:58
Information générale
Forum:
Visual FoxPro
Catégorie:
Base de données, Tables, Vues, Index et syntaxe SQL
Versions des environnements
Visual FoxPro:
VFP 9 SP2
OS:
Windows XP SP2
Network:
Windows XP
Database:
Visual FoxPro
Divers
Thread ID:
01511706
Message ID:
01511800
Vues:
47
i need to use this with pivot table, not with the report writer

i was doing like this, but i desired to do this with select - sql.
CLOSE ALL
CREATE TABLE acmast (accode N(6), acname c(50),opamt N(10,2))
SELECT acmast
INDEX ON accode TAG accode
INSERT INTO acmast (accode,acname,opamt) VALUES (1, 'party name 1', 54200)
INSERT INTO acmast (accode,acname,opamt) VALUES (2, 'party name 2', 24580)

CREATE TABLE sales (idno N(6), billno c(6), billdt d, accode N(6), qty N(7,2), amt N(10,2))
SELECT sales
INDEX ON accode TAG accode
INSERT INTO sales (idno, billno , billdt , accode , qty , amt ) VALUES (1, 'aa/101', DATE(2011,4,04),1,22,509)
INSERT INTO sales (idno, billno , billdt , accode , qty , amt ) VALUES (2, 'aa/102', DATE(2011,4,04),2,11,342)
INSERT INTO sales (idno, billno , billdt , accode , qty , amt ) VALUES (3, 'aa/103', DATE(2011,4,14),1,28,852)
INSERT INTO sales (idno, billno , billdt , accode , qty , amt ) VALUES (4, 'aa/104', DATE(2011,4,04),2,15,514)
INSERT INTO sales (idno, billno , billdt , accode , qty , amt ) VALUES (5, 'aa/105', DATE(2011,4,24),1,18,654)

LOCAL lcalias
lcalias=SYS(2015)

SELECT sales.billno,sales.billdt, sales.accode, acmast.acname, 0000000.00 AS opamt, sales.qty, sales.amt ;
FROM sales ;
LEFT JOIN acmast ON sales.accode=acmast.accode INTO TABLE (lcalias) ORDER BY 3
SELECT (lcalias)
BROWSE 
USE 
USE (lcalias) AGAIN IN 0 ALIAS tempcurs 
SELECT tempcurs 
GO TOP
LOCAL m.lcaccode
DO WHILE NOT EOF()
   m.lcaccode=tempcurs.accode
   IF SEEK(m.lcaccode,'acmast','accode')
      REPL tempcurs.opamt WITH acmast.opamt IN tempcurs
   ENDIF
   DO WHILE tempcurs.accode=m.lcaccode
      SKIP 
   ENDDO
ENDDO
BROWSE

USE IN tempcurs 
USE (lcalias)
BROWSE 


*** excel.automation here
DATAPATH=SYS(5)+CURDIR()
oExcel = CREATEOBJECT("excel.application")
oExcel.APPLICATION.VISIBLE = .T.
oWorkbook = oExcel.Workbooks.ADD()
oTargetSheet = oWorkbook.Sheets.ADD()
oTargetRange = oTargetSheet.RANGE("A2")
oPivotCache = oWorkbook.PivotCaches.ADD( 2 ) && external data
oPivotCache.CONNECTION = "OLEDB;Provider=vfpoledb.1;data source=" + DATAPATH
oPivotCache.Commandtext = "select * from &lcalias "
oPivotTable = oPivotCache.CreatePivotTable( oTargetRange, "PivotTable" )
oPivotTable.PivotFields("acname").ORIENTATION = 1 && row
oPivotTable.PivotFields("billdt").ORIENTATION = 2 && column
oPivotTable.PivotFields("opamt").ORIENTATION = 1 && row
oPivotTable.PivotFields("qty").ORIENTATION = 4 && data
oPivotTable.PivotFields("amt").ORIENTATION = 4 && data

oPivotTable.FORMAT(13)

oTargetSheet.COLUMNS.AUTOFIT
warm regards,
mk.
Précédent
Répondre
Fil
Voir

Click here to load this message in the networking platform