On Thu, 13 Jul 2006 10:33:28 -0230, Tim Marshall
<TIMMY!@PurplePandaChasers.Moertheriumwrote:
Quote:
>The SQL looks all right to me, though that's just a quuick glance
>through it. However, if you're getting results in SQL Plus, then you
>shuld be fine.
On Thu, 13 Jul 2006 10:33:28 -0230, Tim Marshall
<TIMMY!@PurplePandaChasers.Moertheriumwrote:
Quote:
>The SQL looks all right to me, though that's just a quuick glance
>through it. However, if you're getting results in SQL Plus, then you
>shuld be fine.
Well I banged my head long enough on DAO. After reading some threads on
DAO and its relationship to Jet, I thought ADO probably was a better way
to go. I've got it to work with ADO with the OLEDB provided with Oracle
Express. Couple thanks here to several sources. First an excellent post
by an Oracle Express user on Oracle Technology Network per
http://forums.oracle.com/forums/thre...79316�.
Also many thanks to Access 2k2 Enterprise Developer's Handbook which
provided some great information. I've also learned that in ADO you don't
need the semi-colon at the end. So here is the test that worked:
=====================>Begin Code>===================================>
Sub TestADO_DLL_SQL()
Dim cnn As ADODB.Connection
Dim strSQL As String
Dim rst As ADODB.Recordset
Set cnn = New ADODB.Connection
Call SetConStr
'works short version / test
' strSQL = "create or replace view sc.vw_tblorderscuryr_test as " & _
' "select orderno, pdneworder, estrev, estcgs, " & _
' "case when " & Chr(40) & "substr" & Chr(40) & "buscode,-3" &
Chr(41) & " between 100 and 199" & Chr(41) & " then " & Chr(39) & "bu1"
& Chr(39) & " when " & Chr(40) & "substr" & Chr(40) & "buscode,-3" &
Chr(41) & " between 200 and 299" & Chr(41) & " then " & Chr(39) & "bu2"
& Chr(39) & " when " & Chr(40) & "substr" & Chr(40) & "buscode,-3" &
Chr(41) & " between 300 and 399" & Chr(41) & " then " & Chr(39) & "bu3"
& Chr(39) & " end as busunit " & _
' "from sc.tblorderscuryr"
strSQL = "CREATE OR REPLACE VIEW sc.vw_tblOrdersCurYr_rev2 AS " & _
"SELECT OrderNo, PdNewOrder, EstRev, EstCGS, " & _
"case when (substr(BusCode,-3) between 100 and 199) then " &
Chr(39) & "BU" & Chr(39) & "||" & Chr(39) & "1" & Chr(39) & " when
(substr(BusCode,-3) between 200 and 299) then " & Chr(39) & "BU" &
Chr(39) & "||" & Chr(39) & "2" & Chr(39) & " when (substr(BusCode,-3)
between 300 and 399) then " & Chr(39) & "BU" & Chr(39) & "||" & Chr(39)
& "3" & Chr(39) & " end as BusUnit, " & _
"case when Length(MktCode) = 4 then case when
(substr(MktCode,-2) between 10 and 19) then " & Chr(39) & "VM" & Chr(39)
& "||" & Chr(39) & "1" & Chr(39) & " when (substr(MktCode,-2) between 20
and 29) then " & Chr(39) & "VM" & Chr(39) & "||" & Chr(39) & "2" &
Chr(39) & " when (substr(MktCode,-2) between 30 and 39) then " & Chr(39)
& "VM" & Chr(39) & "||" & Chr(39) & "3" & Chr(39) & " when
(substr(MktCode,-2) between 40 and 49) then " & Chr(39) & "VM" & Chr(39)
& "||" & Chr(39) & "4" & Chr(39) & " when (substr(MktCode,-2) between 50
and 59) then " & Chr(39) & "VM" & Chr(39) & "||" & Chr(39) & "5" &
Chr(39) & " when (substr(MktCode,-2) between 60 and 69) then " & Chr(39)
& "VM" & Chr(39) & "||" & Chr(39) & "6" & Chr(39) & " when
(substr(MktCode,-2) between 70 and 79) then " & Chr(39) & "VM" & Chr(39)
& "||" & Chr(39) & "7" & Chr(39) & " when (substr(MktCode,-2) between 80
and 89) then " & Chr(39) & "VM" & Chr(39) & "||" & Chr(39) & "8" &
Chr(39) & " when (substr(MktCode,-2) between 90 and 99) then " _
& Chr(39) & "VM" & Chr(39) & "||" & Chr(39) & "9" & Chr(39) & "
when (substr(MktCode,-2) between 100 and 109) then " & Chr(39) & "VM" &
Chr(39) & "||" & Chr(39) & "10" & Chr(39) & " end when Length(MktCode) =
5 then " & Chr(39) & "VM" & Chr(39) & "||" & Chr(39) & "10" & Chr(39) &
" end as VertMkt, " & _
"case when (substr(BrchNo,-4) between 1500 and 1550) then " &
Chr(39) & "Rgn" & Chr(39) & "||" & Chr(39) & "1" & Chr(39) & " when
(substr(BrchNo,-4) between 2500 and 2550) then " & Chr(39) & "Rgn" &
Chr(39) & "||" & Chr(39) & "2" & Chr(39) & " when (substr(BrchNo,-4)
between 3500 and 3550) then " & Chr(39) & "Rgn" & Chr(39) & "||" &
Chr(39) & "3" & Chr(39) & " when (substr(BrchNo,-4) between 4500 and
4550) then " & Chr(39) & "Rgn" & Chr(39) & "||" & Chr(39) & "4" &
Chr(39) & " when (substr(BrchNo,-4) between 5500 and 5500) then " &
Chr(39) & "Rgn" & Chr(39) & "||" & Chr(39) & "5" & Chr(39) & " when
(substr(BrchNo,-4) between 6500 and 6550) then " & Chr(39) & "Rgn" &
Chr(39) & "||" & Chr(39) & "6" & Chr(39) & " when (substr(BrchNo,-4)
between 7500 and 7550) then " & Chr(39) & "Rgn" & Chr(39) & "||" &
Chr(39) & "7" & Chr(39) & " end as Rgn, " & _
"case when (substr(ProdNo,-3) between 100 and 199) then " &
Chr(39) & "LOB" & Chr(39) & "||" & Chr(39) & "1" & Chr(39) & " when
(substr(ProdNo,-3) between 200 and 299) then " & Chr(39) & "LOB" &
Chr(39) & "||" & Chr(39) & "2" & Chr(39) & " when (substr(ProdNo,-3)
between 300 and 399) then " & Chr(39) & "LOB" & Chr(39) & "||" & Chr(39)
& "3" & Chr(39) & " when (substr(ProdNo,-3) between 400 and 499) then "
& Chr(39) & "LOB" & Chr(39) & "||" & Chr(39) & "4" & Chr(39) & " when
(substr(ProdNo,-3) between 500 and 599) then " & Chr(39) & "LOB" &
Chr(39) & "||" & Chr(39) & "5" & Chr(39) & " when (substr(ProdNo,-3)
between 600 and 699) then " & Chr(39) & "LOB" & Chr(39) & "||" & Chr(39)
& "6" & Chr(39) & " when (substr(ProdNo,-3) between 700 and 799) then "
& Chr(39) & "LOB" & Chr(39) & "||" & Chr(39) & "7" & Chr(39) & " when
(substr(ProdNo,-3) between 800 and 899) then " & Chr(39) & "LOB" &
Chr(39) & "||" & Chr(39) & "8" & Chr(39) & " end as LineOfBus " & _
"from sc.tblOrdersCurYr"
Debug.Print strSQL
With cnn
.ConnectionString = strOleDBOrcCnn
.Open
End With
Set rst = New ADODB.Recordset
rst.Open CStr(strSQL), cnn, adOpenKeyset, adLockOptimistic
Set rst = Nothing
Set cnn = Nothing
End Sub
=====================<End Code<=====================================<
Connection string (w/code):
=====================>Begin Code>===================================>
Public strOleDBOrcCnn As String
Sub SetConStr()
Dim strUID As String, strPswd As String
Forms("frmMain").Refresh
strOleDBOrcCnn = ""
If IsNull(Forms("frmMain").Controls("txtUserID").Valu e) Then
MsgBox "Please enter your User ID!", , "Enter User ID"
Exit Sub
End If
If IsNull(Forms("frmMain").Controls("txtPswd").Value) Then
MsgBox "Please enter your Password!", , "Enter Password"
Exit Sub
End If
strUID = Forms("frmMain").Controls("txtUserID").Value
strPswd = Forms("frmMain").Controls("txtPswd").Value
strOleDBOrcCnn = "Provider = OraOLEDB.Oracle;" & _
"Data Source = XE;" & _
"User Id = " & strUID & ";" & _
"Password = " & strPswd
End Sub
=====================<End Code<=====================================<
--
Regards,
Greg Strong