LoriNeirynck
asked on
OO4O Bind variables
I am creating a report and ask the users to select which divisions they want to see the report for. They can choose mulitple divisions. I am trying to figure out if it is possible to select all the information I need without having to create a new bind variable for each division and then changing my sql statement to fit the number of divisions. I've tried the following with little success.
Private opaDivisions As OraParamArray
Private rs As OraDynaset
DB.Parameters.AddTable "DIVISIONS", ORAPARM_INPUT, ORATYPE_VARCHAR, 10, 5
Set opaDivisions = DB.Parameters("DIVISIONS")
opaDivisions.put_Value "M", 0
opaDivisions.put_Value "T", 1
opaDivisions.put_Value "L", 2
strSql = "SELECT " _
& "Order.Cabinet_style_info. ItemType, " _
& "Order.Barcode.Location Location, " _
& "B.n_status_code Status, " _
& "count (Order.Barcode.Location) " _
& "FROM Order.tbl_barcode B " _
& "INNER JOIN Order.tbl_order_header OH " _
& "ON B.n_order_number = OH.n_order_number " _
& "AND OH.c_division IN (:DIVISIONS) " _
& "WHERE B.n_status_code < 9 " _
& "AND B.n_deleted_flag = 0 " _
& "GROUP BY Order.Cabinet_style_info.I temType , Order.Barcode.Location, B.n_status_code"
Set rs = DB.CreateDynaset(strSql, ORADYN_READONLY)
This will only return the records for division "M" or whatever division I set first.
Any way I can do something like this without having the code simply build the sql string to say exactly which divisions I want to select?
Thanks.
Private opaDivisions As OraParamArray
Private rs As OraDynaset
DB.Parameters.AddTable "DIVISIONS", ORAPARM_INPUT, ORATYPE_VARCHAR, 10, 5
Set opaDivisions = DB.Parameters("DIVISIONS")
opaDivisions.put_Value "M", 0
opaDivisions.put_Value "T", 1
opaDivisions.put_Value "L", 2
strSql = "SELECT " _
& "Order.Cabinet_style_info.
& "Order.Barcode.Location Location, " _
& "B.n_status_code Status, " _
& "count (Order.Barcode.Location) " _
& "FROM Order.tbl_barcode B " _
& "INNER JOIN Order.tbl_order_header OH " _
& "ON B.n_order_number = OH.n_order_number " _
& "AND OH.c_division IN (:DIVISIONS) " _
& "WHERE B.n_status_code < 9 " _
& "AND B.n_deleted_flag = 0 " _
& "GROUP BY Order.Cabinet_style_info.I
Set rs = DB.CreateDynaset(strSql, ORADYN_READONLY)
This will only return the records for division "M" or whatever division I set first.
Any way I can do something like this without having the code simply build the sql string to say exactly which divisions I want to select?
Thanks.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Private rs As OraDynaset
DB.Parameters.Add "Division", "", ORATYPE_VARCHAR2
DB.Parameters("Division").
strSql = "SELECT " _
& "Order.Cabinet_style_info.
& "Order.Barcode.Location Location, " _
& "B.n_status_code Status, " _
& "count (Order.Barcode.Location) " _
& "FROM Order.tbl_barcode B " _
& "INNER JOIN Order.tbl_order_header OH " _
& "ON B.n_order_number = OH.n_order_number " _
& "INSTR(:DIVISION, OH.c_division) > 0 " _
& "WHERE B.n_status_code < 9 " _
& "AND B.n_deleted_flag = 0 " _
& "GROUP BY Order.Cabinet_style_info.I
Set rs = DB.CreateDynaset(strSql, ORADYN_READONLY)
Then I simply build the string for the bind variable and do not have to change my sql statement.