Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 4
Default SQL in VBA to Access a Database and create Report

Greetings.

I've started to program a Microsoft Query in VBA, in order to create an
Excel report.

Presently I'm stuck with a code and need to study further in SQL.

Is there any reference in Internet where I can learn to program in SQL?


Anyway, I leave you my question, hoping someone can help me:

Imagine the tables:

FlownRevenue05
--
AgentCode (integer)
Tickets (integer)
Revenue (float)
JourneyType (char 1, "D" for Domestic Sales, "I" for International)

Groups
--
AgentCode
GroupName (char 10)


The AgentCode are connected via a Many(FlownRev)-One(Groups).

The rabbit I'm trying to pull out now is combine, in the same report, the
following data:


AgentCode CouponsDOM RevenueDOM CouponsINT RevenueINT


And for that, I tried the following SQL:

Quote:
..Sql = Join$(Array( _
"SELECT G05.`Group Name`, FR05.`Agent Code`, Sum(FR05.Coupons) as [CpnsDOM],
Sum(FR05.`Revenue LC`) as [RevDOM], _
"FROM {oj `C:\My Documents\Temporário\Unify\db2006 November-onward
Compact`.`Flown Revenue 2005` FR05", _
"LEFT OUTER JOIN `C:\My Documents\Temporário\Unify\db2006 November-onward
Compact`.Groups G05", _
"ON FR05.`Agent Code` = G05.`Agent Code`}", _
"WHERE FR05.`Journey Type` = 'D' and G05.`Group Name` = '" &
cmdComboBox.Text & "'", _
"GROUP BY G05.`Group Name`, FR05.`Agent Code`", _
"UNION SELECT G05.`Group Name`, FR05.`Agent Code`, Sum(FR05.Coupons) as
[CpnsINT], Sum(FR05.`Revenue LC`) as [RevINT], _
"FROM {oj `C:\My Documents\Temporário\Unify\db2006 November-onward
Compact`.`Flown Revenue 2005` FR05", _
"LEFT OUTER JOIN `C:\My Documents\Temporário\Unify\db2006 November-onward
Compact`.Groups G05", _
"ON FR05.`Agent Code` = G05.`Agent Code`}", _
"WHERE FR05.`Journey Type` = 'I' and G05.`Group Name` = '" &
cmdComboBox.Text & "'", _
"GROUP BY G05.`Group Name`, FR05.`Agent Code`"), vbCr)



Using the "UNION SELECT" I only get the headers AgentCode CouponsDOM
RevenueDOM, and the values appear to be the sum of Domestic and
International.

I hope this is possible, probably it's just a question of arranging the
proper SQL.
Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
VBA Code to create PIVOT in Excel from access database ST Excel Discussion (Misc queries) 1 July 26th 06 06:38 PM
Create Pivot from access database by VBA ST Excel Discussion (Misc queries) 0 July 26th 06 04:31 AM
Create Access like report in Excel. J-Sherm-Dwyer Excel Programming 1 February 17th 05 08:21 PM
Create Access like report in Excel. J-Sherm-Dwyer Excel Programming 0 February 17th 05 08:03 PM
Access 2000: Print Database name in Report footer Jeff[_43_] Excel Programming 1 December 10th 04 08:46 PM


All times are GMT +1. The time now is 12:26 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"