我正在尝试在SQL中使用IF-ELSE语句并在vba中执行查询。下面的代码基于硬编码过滤器返回excel中的表。但我需要做什么,如果以防万一,我只需要特定日期范围(例如,比如一个月)和特定位置的结果。该位置在代码中称为Credited Office。任何帮助将非常感激。
提前致谢!
objMyCmd.CommandText = " SELECT a.[RDT_FileID],a.[Master Policy Number], a.[Work item /Submission no#],a.[Insured Name], a.[Credited Office]," & _
" a.[Credited Underwriter], a.[Product Line], a.[Product Line Subtype], a.[Current Status], a.[Effective Date], a.[Expiry Date], a.[Premium in USD $] " & _
" FROM DB1[![enter image description here][1]][1].dbo.View_Property_Rater_Of_Record a " & _
" WHERE a.[Master Policy Number] Is Not Null " & _
" AND a.[RDT_FileID] is null " & _
" AND a.[Product Line Subtype] <> '0102-Marine' " & _
" AND a.[Effective Date] >= '2014-04-01' " & _
" AND a.[Current Status] ='Bound' "
objMyCmd.CommandType = adCmdText
objMyCmd.Execute
这是代码,我试图搜索特定日期的结果
'Capture the filters that determin the range of the data that reports are based on
Sheets("Main").Activate
If IsEmpty(Range("C10")) Then PED(0) = 42461 Else PED(0) = Range("C10").Value 'Lower bound of Effective Dates, defaults to 4/1/2014
If IsEmpty(Range("D10")) Then PED(1) = 407703 Else PED(1) = Range("D10").Value 'Upper bound of Effective Dates, defaults to 4/1/3014
If Range("D4") = "" Then Reg = "All Regions" Else Reg = Range("D4").Value 'Office, defaults to "All Regions"
' Step 8 - Create #TmpFileFltr incorporating all the data filters to #TmpFile
Sql = "Select * " _
& "into #TmpFileFltr " _
& "from #TmpFile " _
& "where EffectiveDate >= " & PED(0) & " and EffectiveDate <= " & PED(1) & " "