1
サーバー:LBOSS\BACKOFFICE  
ID:さ  
DB名:LogiDB  
パスワード:  
テーブル RPT_SUB、RPT_FIN  
F04、F254、F1056、F11057....  

SQL データを Excel スプレッドシートに取り込もうとしました。

誰か助けて?
ここに情報があります。

他のサーバーからこの vba マクロを見つけました。
では、このデータをサーバーに使用するにはどうすればよいでしょうか?
または任意のアイデア?

Sub start()

'Call init
Dim strQuery As String
Dim strStartDate As String

strStartDate = "'" & Cells(2, 4).Value & "'"

' No Category Report
Call Query("select report_daily_category(" & strStartDate & ", null)", _
Cells(5, 4))
' No Category GST
Call Query("SELECT report_daily_tax(" & strStartDate & ",1,null)", _
Cells(5, 7))
' Category Description
Call Query("SELECT description FROM category where not obsolete ORDER BY list_priority", _
Cells(6, 3))
' Category Report
Call Query("SELECT report_daily_category(" & strStartDate & ",category_id) FROM category where not obsolete ORDER BY list_priority", _
Cells(6, 4))
' Category GST Report
Call Query("SELECT report_daily_tax(" & strStartDate & ",1,category_id) from category where not obsolete ORDER BY list_priority", _
Cells(6, 7))
' Lotto Report
'Call Query("SELECT report_daily_lotto(" & strStartDate & ", true)", _
Cells(14, 7))
'Call Query("SELECT report_daily_lotto(" & strStartDate & ", false)", _
Cells(16, 7))
' Tax Description
Call Query("SELECT description FROM tax_rule where not disabled ORDER BY tax_id", _
Cells(22, 3))
' Tax Report
Call Query("SELECT report_daily_tax(" & strStartDate & ",tax_id) FROM tax_rule where not disabled ORDER BY tax_id", _
Cells(22, 4))
' Vendor Coupon
Call Query("select report_daily_coupon(" & strStartDate & ", null, null)", _
Cells(30, 4))
' Discount
Call Query("select report_daily_discount(" & strStartDate & ", true)", _
Cells(32, 4))
' Reward Point + Store Credit
Call Query("select report_daily_storecredit(" & strStartDate & ")", _
Cells(33, 4))
' Refund
Call Query("select report_daily_refund(" & strStartDate & ", true)", _
Cells(35, 4))
' Refund GST; Included in <Tax Report>
Call Query("SELECT report_daily_refund(" & strStartDate & ", null)", _
Cells(37, 4))
' Customer Count
Call Query("select count(*) from receipt where time >= " & strStartDate & " and time < cast(" & strStartDate & " as timestamp) + interval '1 day'", _
Cells(42, 4))
' Payment Description
Call Query("SELECT payment FROM payment_method ORDER BY list_priority", _
Cells(46, 3))
' Payment Report
Call Query("SELECT report_daily_payment(" & strStartDate & ",paymethod_id, null) FROM payment_method ORDER BY list_priority", _
Cells(46, 4))

' ROA
Call Query("SELECT report_daily_roa(" & strStartDate & ")", _
Cells(41, 12))

Call cleanup

End Sub
Sub init()
End Sub

Sub cleanup()
    Cells.Select
    With Selection
        .VerticalAlignment = xlCenter
        .HorizontalAlignment = xlRight
        .Font.Name = "Courier New"
        .Font.Size = 9
    End With
    For Each obj In ActiveSheet.QueryTables
        obj.Delete
    Next

End Sub
' Array("ODBC;DSN=PostgreSQL30;DATABASE=pos1;SERVER=192.168.1.200;PORT=5432;UID=postgres;PWD=nopass;ReadOnly=0;FakeOidIndex=0;Show")
Sub Query(strQuery As Variant, Pos As Variant)
    Dim ConnectionString As Variant
    ConnectionString = Array( _
        Array("ODBC;DSN=PostgreSQL30;DATABASE=pos1u;SERVER=192.168.1.250;PORT=5432;UID=postgres;PWD=nopass;ReadOnly=0;FakeOidIndex=0;ShowOidC"), _
        Array("OidColumn=0;RowVersioning=0;ShowSystemTables=0;ConnSettings=;Fetch=100;Socket=4096;UnknownSizes=0;MaxVarcharSize=254;MaxLongVar"), _
        Array("charSize=8190;Debug=0;CommLog=0;Optimizer=1;Ksqo=1;UseDeclareFetch=0;TextAsLongVarchar=1;UnknownsAsLongVarchar=0;BoolsAsChar=1;"), _
        Array("Parse=0;CancelAsFreeStmt=0;ExtraSysTablePrefixes=dd_;;LFConversion=1;UpdatableCursors=1;DisallowPremature=0;TrueIsMinus1=0") _
    )
    With ActiveSheet.QueryTables.Add(Connection:=ConnectionString, Destination:=Pos)
        .CommandText = Array(strQuery)
        .Name = "Query"
        .FieldNames = False
        .RowNumbers = False
        .FillAdjacentFormulas = False
        .PreserveFormatting = True
        .RefreshOnFileOpen = False
        .BackgroundQuery = True
        .RefreshStyle = xlOverwriteCells
        .SavePassword = True
        .SaveData = True
        .AdjustColumnWidth = False
        .RefreshPeriod = 0
        .PreserveColumnInfo = True
        .Refresh BackgroundQuery:=False
    End With

End Sub
4

1 に答える 1

0

サブクエリ(...)を見てください。ConnectionString = ... で始まる行があります。次のように変更します。

ConnectionString = "ODBC;DATABASE=LogiDB;SERVER=LBOSS\BACKOFFICE;UID=sa;PWD=password"

PWD= の後にパスワードを入力し、 Start() サブで SQL クエリを編集します。基本的には問題なく動作するはずです。

于 2012-08-24T13:43:12.093 に答える