Visual Basic Code , VB.NET Code, VB Code
  Home   :  Code   :  Forums   :  Submit   :  Mailing List   :  About   :  Contact
A1VBCode Forums
Home      Members   Calendar   Who's On
Welcome Guest ( Login | Register )
      

Home » Classic Visual Basic (VB 6 or earlier) » VBA(Excel, Word, etc...) » Column alias


Column aliasExpand / Collapse
Author
Message
Posted 9/23/2009 1:26:02 PM
Forum Newbie

Forum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum Newbie

Group: Forum Members
Last Login: 9/28/2009 5:34:43 PM
Posts: 4, Visits: 11
I would like to put column aliases on some of the fields in the SELECT statement.

Private Sub CommandButton1_Click()
Dim NumList As String
Dim SourceBook As Workbook
Dim ListSheet As Worksheet
Dim QuerySheet As Worksheet
Dim Query As QueryTable
Dim Numb As String

Set SourceBook = Application.ActiveWorkbook
Set ListSheet = SourceBook.Worksheets("Main")
Set QuerySheet = SourceBook.Worksheets("MONEY")
Numb = Range("H6")


If ListSheet.Cells(6, 8).Value = "" Then Exit Sub
NumList = "'" & ListSheet.Cells(6, 8).Value & "'"

Set Query = QuerySheet.QueryTables("MNY")
Query.Sql = "SELECT NUMB_TBLE.NUMB_NAME, extract(month from NUMB_DATES_TBLE.DAY_MTH_YR) " _
& "FROM JES.NUMB TBLE NUMB TBLE,
JES.NUMB_DATES_TBLE NUMB_DATES_TBLE" _
& "WHERE NUMB_TBLE.NUMB_ID = NUMB_DATES_TBLE.NUMB_ID AND NUMB_TBLE.NUMB_CODE IN (" & NumList & ") " _
& "Group by numb_tble.numb_name,
extract(month from NUMB_DATES_TBLE.DAY_MTH_YR)




Query.Refresh (False)


End Sub

I want to alias the column NUMB_TBLE.NUMB_NAME, I want it to say LAST_NAME

I have tried NUMB_TBLE.NUMB_NAME AS LAST_NAME. It works but it changes the order of the columns. I do not want the order of the columns to change.

When the query runs, in Excel, the column headings are DAY_MTH_YR and LAST_NAME

If I do not use the alias, the column headings in Excel are NUMB_NAME, DAY_MTH_YR.

I want the order to still be Name of the person, Date of the transaction.

When I use the alias, it becomes Date of the transaction, Name of the person

The order changes.

How do I alias the columns without effecting the order of the columns.

I connect to the Oracle database and the result set is put into excel
Post #28232
« Prev Topic | Next Topic »


Reading This TopicExpand / Collapse
Active Users: 1 (1 guest, 0 members, 0 anonymous members)
No members currently viewing this topic.
Forum Moderators: Admin, Mod, Mark, Keithuk

PermissionsExpand / Collapse

All times are GMT -5:00, Time now is 2:22pm