SERVER:LBOSS\BACKOFFICE ID:sa DB NAME:LogiDB PASSWORD: Table RPT_SUB,RPT_FIN F04,F254,F1056,F11057....
我尝试将SQL数据引入Excel Spread表。
有人帮帮我吗? 这是信息;
我从其他服务器找到了这个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
答案 0 :(得分:0)
查看Sub Query(...)。有一行以ConnectionString = ....开头 将其更改为:
ConnectionString = "ODBC;DATABASE=LogiDB;SERVER=LBOSS\BACKOFFICE;UID=sa;PWD=password"
在PWD =之后输入您的密码,并在Start()子目录中编辑SQL查询。基本上应该工作正常。