18.10.2013 Views

SQL2GMS - GAMS

SQL2GMS - GAMS

SQL2GMS - GAMS

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

26<br />

<strong>SQL2GMS</strong><br />

parameter profit(prd,loc,y) /<br />

$include profit.inc<br />

/;<br />

display profit;<br />

The same example imported through a GDX file can look like:<br />

$ontext<br />

Example database access with <strong>SQL2GMS</strong> (OLEDB)<br />

Multiple queries in one call, store in GDX file<br />

$offtext<br />

$onecho > cmd.txt<br />

C=Provider=Microsoft.Jet.OLEDB.4.0;Data Source=%system.fp%sample.mdb<br />

X=sample.gdx<br />

Q1=select distinct(year) from data<br />

s1=year<br />

Q2=select distinct(loc) from data<br />

s2=loc<br />

Q3=select distinct(prod) from data<br />

s3=prd<br />

Q4=select prod,loc,year,sales from data<br />

a4=sales<br />

Q5=select prod,loc,year,profit from data<br />

a5=profit<br />

$offecho<br />

$call =sql2gms @cmd.txt<br />

$call =gdxviewer sample.gdx<br />

set y 'years';<br />

set loc 'locations';<br />

set prd 'products';<br />

parameter sales(prd,loc,y);<br />

parameter profit(prd,loc,y);<br />

$gdxin 'sample.gdx'<br />

$load y=year loc prd sales profit<br />

display sales;<br />

display profit;<br />

The call to gdxviewer will display the gdx file in the stand-alone GDX viewer.<br />

16 Strategies<br />

Strategies<br />

Including SQL statements to extract data from a database inside your model can lead to a number of<br />

difficulties:<br />

The database can change between runs, leading to results that are not reproducible. A<br />

© 2010 <strong>GAMS</strong> Development Coorporation

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!