|
SQL语句中where条件为两种类型参数值如何互换查询,谢谢
请老师给看看下面的代码
中如果字段值为两种类型的参数,如何修改代码?谢谢
参数:Item Number(文本类型);PO Number(数值型)
Sub limonet_New()
'XXXXXXXXXXXXXXXXXXXXXXX
Dim rng As Range
Dim P As String
Dim Q As String
P = Sheet2.Range("A1") '条件参数 字段名 Item Number;PO Number
Q = Sheet2.Range("B1") '条件参数 数据源中字段值 Item Number(文本类型);PO Number(数值型)
Set rng = ActiveSheet.Range("B1") ' 指定要设置背景颜色的单元格
rng.Interior.ColorIndex = 6 ' 设置背景颜色的索引值,可以根据需要更改
'XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
Range("A3:M3").Select
Range(Selection, Selection.End(xlDown)).Select
Selection.ClearContents
Dim strSQL As String, CN As Object, Rst As Object
Set CN = CreateObject("ADODB.connection")
CN.Open "Provider=Microsoft.ACE.OLEDB.12.0;Extended Properties=excel 12.0;Data Source=" & ThisWorkbook.FullName
'Worksheets.Add(after:=Worksheets(Sheets.Count)).Name = "TempSheet" '添加工作表名称
'XXXXXXXXXXXXX
'绝对路径
'strPath= "D:\Pro_Reports\Tables\RICE0010-Open PO.xlsx"
'strcnn="Provider=Microsoft.ACE.OLEDB.12.0;Extended Properties=excel 12.0;Data Source=" & strPath
strSQL = "Select [PO Number],[PO Line],[Line Type],[Item Number],[Description],[Buyer],[Closed_Code],[Vendor],[Qty],[Qty Rec'd],[Qty Accept],[Need By],[Promise] From [excel 12.0;Database=" & ThisWorkbook.Path & "\Global_OPEN_PO.xlsx].[Global_OPEN_PO$] where [" & P & "]='" & Q & "' ORDER BY [Need By] ,[PO Line]"
'xxxxxxxxxxxxxxxxxxxxxxxxxxxxx
Set Rst = CN.Execute(strSQL)
For i = 1 To Rst.Fields.Count
Cells(2, i) = Rst.Fields(i - 1).Name '由第二行开始添加表头字段名
Next i
Range("A3").CopyFromRecordset Rst
'Range("A2:M2").Select
' Selection.AutoFilter
'Range("a3").CopyFromRecordset CN.Execute(strSQL)
CN.Close
Set CN = Nothing
|
|