SQL2GMS - GAMS
SQL2GMS - GAMS
SQL2GMS - GAMS
Create successful ePaper yourself
Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.
6<br />
<strong>SQL2GMS</strong><br />
new york 100<br />
los angeles 120<br />
san francisco 105<br />
washington dc 102<br />
This means we have to map ‘new york' to ‘NY' etc. This mapping can be done in two places: either in<br />
<strong>GAMS</strong> or in the database.<br />
When we export the table directly (with the option ‘Quote Blanks' turned on), we get:<br />
* -----------------------------------------------------<br />
* <strong>SQL2GMS</strong> Version 3.0, November 2006<br />
* Erwin Kalvelagen, <strong>GAMS</strong> Development Corp<br />
* -----------------------------------------------------<br />
* ADO version: 2.8<br />
* Connection string: Driver={Microsoft Access Driver (*.mdb)}; Dbq=d:<br />
\sql2gms\sample.mdb<br />
* Provider: MSDASQL<br />
* Query: SELECT city, value<br />
* FROM [example table]<br />
* -----------------------------------------------------<br />
'new york' 100<br />
'los angeles' 120<br />
'san francisco' 105<br />
'washington dc' 102<br />
* -----------------------------------------------------<br />
As the index elements contain blanks, the option Quote Blanks was used. To import this file and<br />
convert it to a different index space we can use the following <strong>GAMS</strong> code:<br />
set i /NY,DC,LA,SF/;<br />
set idb 'from database' /<br />
'new york',<br />
'washington dc',<br />
'los angeles',<br />
'san francisco'<br />
/;<br />
parameter dbdata(idb) /<br />
$include data.inc<br />
/;<br />
set mapindx(i,idb) /<br />
NY.'new york'<br />
DC.'washington dc'<br />
LA.'los angeles'<br />
SF.'san francisco'<br />
/;<br />
parameter data(i);<br />
data(i) = sum(mapindx(i,idb), dbdata(idb));<br />
display data;<br />
The second approach is to handle the mapping inside the database. We can introduce a mapping table<br />
that looks like:<br />
© 2010 <strong>GAMS</strong> Development Coorporation