MS Visual Studio (Reporting Services) - visual-studio

I've worked in SSRS for years but have never learned what this type of coding is actually named (which makes searching for solutions difficult), can anyone help please? Below is an example which allows the developer to have the code run as one continuous string. It also, if you're not familiar, allows for many powerful functions to be used that would otherwise (to my knowledge) not be available (e.g., IIF's, INSTR(JOIN()), SWITCH's, etc.).
=
" select distinct bn " &
" into #ST " &
" from frm_cr_2021 a " &
" join Md..nui_crssw b " &
" ON a.rc=b.cy"&MID(YEAR(Parameters!frm_dt.Value),3,2)&"_rc" &
" join nd_bs..dg_cv c " &
" on b.nd=c.nd " &
" where a.f_Dt<=#frm_dt and a.tr_dt>=#frmy_dt " &
"(select distinct c.ln,a.RC,A.Tr_Lv,a.P_Typ,a.P_Gp,a.Eff_Date,a.Term_Date from frm_"&YEAR(Parameters!frm_dt.Value)&" a "

Related

Passing a MS Access Form date into an Oracle SQL

I'm using MS Access to pull some data from an Oracle server via a pass-through query. The user is presented with a form in which they can input some variables (such as a date range). I would like the Oracle SQL to be able to pick up the two date fields from the form.
The current SQL (which doesn't work) is as follows:
SELECT a.I_LOAN_NUM, a.I_LOAN_SUB_ALLOC, c.N_EXCLV, e.I_GSL_SPNSR, e.N_GSL_SPNSR, b.D_CAL, b.C_LOAN_STAT, g.N_CNTRY
FROM SLD_LOAN_MSTR a
JOIN SLD_LOAN_CDL b on b.I_LOAN_ID = a.I_LOAN_ID
JOIN SLD_EXCLV c on c.I_EXCLV_ID = b.I_EXCLV_ID
JOIN SLD_AC d on d.I_AC_ID = b.I_AC_ID
JOIN SLD_CUST e on e.I_CUST_ID = d.I_CUST_ID
JOIN SLD_DPT_CNTRY f on f.I_DPT_ID = b.I_DPT_ID
JOIN SLD_CNTRY g on g.I_CNTRY_ID = f.I_CNTRY_ID
WHERE (b.C_LOAN_STAT = 'SETTLED' and b.D_CAL between [Forms]![Cost Allocation Form]![Start_Date] and [Forms]![Cost Allocation Form]![End_Date])
ORDER BY b.D_CAL
The above SQL works if I replace the form references with hard coded dates, so I know the SQL is generally good. Example:
WHERE (b.C_LOAN_STAT = 'SETTLED' and b.D_CAL between '01JAN2019' and '01FEB2019')
The error message being generated by the SQL states "ODBC--call failed. [Oracle][ODBC][Ora]ORA-00936: missing expression (#936)"
Both of the date fields in the Form are using the Short Date format.
I'm not sure if this makes any difference or not, but the Form has multiple tabs. From what I've seen from other examples, the Form reference doesn't need to take the tab labels into account.
Thanks
Pass-through queries are executed at the server. In your case the Oracle server doesn't recognize the [Forms]![Cost Allocation Form]![Start_Date] and [Forms]![Cost Allocation Form]![End_Date] attributes.
You could use VBA to dynamically update the query definition of the query to include the form control values. Then execute the query.
Dim strSQL As String
Dim qdf As QueryDef
strSQL = "SELECT a.I_LOAN_NUM, a.I_LOAN_SUB_ALLOC, c.N_EXCLV, e.I_GSL_SPNSR, e.N_GSL_SPNSR, b.D_CAL, b.C_LOAN_STAT, g.N_CNTRY " & _
"FROM SLD_LOAN_MSTR a " & _
"JOIN SLD_LOAN_CDL b on b.I_LOAN_ID = a.I_LOAN_ID " & _
"JOIN SLD_EXCLV c on c.I_EXCLV_ID = b.I_EXCLV_ID " & _
"JOIN SLD_AC d on d.I_AC_ID = b.I_AC_ID " & _
"JOIN SLD_CUST e on e.I_CUST_ID = d.I_CUST_ID " & _
"JOIN SLD_DPT_CNTRY f on f.I_DPT_ID = b.I_DPT_ID " & _
"JOIN SLD_CNTRY g on g.I_CNTRY_ID = f.I_CNTRY_ID " & _
"WHERE (b.C_LOAN_STAT = 'SETTLED' and b.D_CAL between '" & _
[Forms]![Cost Allocation Form]![Start_Date] & "' and '" & [Forms]![Cost Allocation Form]![End_Date] & _
"' ORDER BY b.D_CAL"
Set qdf = CurrentDb.QueryDefs("PassThroughQueryName")
qdf.SQL = strSQL
Also since your using dates, I would suggest you format your dates to the ISO format yyyy-mm-dd
in this case formatting the controls like
Format([Forms]![Cost Allocation Form]![Start_Date], "yyyy-mm-dd") & "' and '" & Format([Forms]![Cost Allocation Form]![End_Date], "yyyy-mm-dd")
Another way would be to just use VBA ADO to access the Oracle Server and retrieve the data. You would still need to build up your SQL string as mentioned here.

Report: Counting number of records, between a number range

MS Access 2013. I need to write a report that shows the number of books inside our storage boxes.
All books purchased are given a unique nbr (SaleID). We store 25 books per box, and 100 books takes 4 boxes. As we sell books, they are removed from their specific boxes, and over time, lets say 30 books are sold. We can then discard one box, and store the remaining 70 books in three boxes. We have thousands of books and hundreds of storage boxes. I need to run a report that shows me how many books are in stock, per every 100 books, so that I can reduce the number of boxes (and save storage space).
The report should show like this:
001 - 100 34 (i.e. 34 books are in stock in the number range 001 to 100.
101 - 200 35 (35 books in stock)
201 - 300 22 (22 books in stock)
301 - 400 60 (60 books in stock)
etc
The query below does what I want, where I enter the criteria of the hundred books being queried. But I need a line on the report, for each hundred books, for all the books we hold.
SELECT tblSale.BookInStock, Count(tblSale.BookInStock) AS [Total Books]
FROM tblSale
WHERE (((tblSale.SaleID) Between 4201 And 4300))
GROUP BY tblSale.BookInStock
HAVING (((tblSale.BookInStock)=Yes));
If someone has any ideas I'd be grateful for your thoughts
Cheers
Nev
Since you have to query every hundred items, coding will be needed to run through every per hundred batch. Therefore, consider creating a temp table from a VBA looped query.
First iteration of loop creates the table replacing previous, then all other iterations append by hundred batches (notice step used to skip iterator forward) across your thousands. By the way, your HAVING clause condition was moved to WHERE clause.
Dim i As Long
Dim sqlStr As String
Dim db As DAO.Database
Dim tbl As TableDef
Set db = CurrentDb
For Each tbl in db.TableDefs
If tbl.Name = "BoxBooksPerHundred" Then
db.TableDefs.Delete(tbl.Name)
End If
Next tbl
For i = 1 to 4300 Step 100 ' ADJUST AS NEEDED
If i = 1 Then
' MAKE-TABLE QUERY
strsql= "SELECT '" & i & " - " & i + 100 & "' AS [HundredRange], tblSale.BookInStock," _
& " Count(tblSale.BookInStock) AS [Total Books]" _
& " INTO BoxBooksPerHundred FROM tblSale" _
& " WHERE (((tblSale.BookInStock)=Yes)) And" _
& " (((tblSale.SaleID) Between " & i & " And " & i + 100 & "))" _
& " GROUP BY '" & i & " - " & i + 100 & "', tblSale.BookInStock;"
db.Execute strSQL, dbFailOnError
Else
' APPEND QUERY
strsql= "INSERT INTO BoxBooksPerHundred (HundredRange, BookInStock, [Total Books])"
& " SELECT '" & i & " - " & i + 100 & "' AS [HundredRange], tblSale.BookInStock," _
& " Count(tblSale.BookInStock) AS [Total Books]" _
& " FROM tblSale" _
& " WHERE (((tblSale.BookInStock)=Yes)) And" _
& " (((tblSale.SaleID) Between " & i & " And " & i + 100 & "))" _
& " GROUP BY '" & i & " - " & i + 100 & "', tblSale.BookInStock;"
db.Execute strSQL, dbFailOnError
End If
Next i
Set tbl = Nothing
Set db = Nothing
Run this loop on the trigger event that opens report. But since quite a bit of data, try triggering on database open if you expect data not to change often. Ultimately, use this temp table, BooksPerHundred, as recordsource for report.

Alternatives to macros for accessing data objects

I'm about to begin implementing a new version of an Email marketing program for my company. The old version of the program program heavily depended on micros and has about 2000 lines to prepare data for an email campaign to be run. But I have read somewhere that macros are not the best solution to run such heavy tasks and it's better we keep them for simple things.
I'm quite new to QV and I'm the kind of person that likes to learn as I go and not complete a big reference book before I start a project. I'm good at C# and Java but I realized QlikView scripts are in either VBScript or JScript. I have no experience with them whatsoever but they don't look very complicated to me at first glance.
What I was wondering was whether there is a better way of handling data in QlikView? That means can I use another programming language or do you suggest I stick to the script languages provided by QV? Because one big problem I've seen is that as macros get larger they become very hard to debug.
In the old version of our program developed by one of my colleagues who has now left the company, as soon as there was an error in preparing the data, all we got was the macros window with no clue about where the error had taken place. As I would like to implement this project incrementally and little by little, I would like to have a good mechanism for trouble shooting rather than goring though a 2000-line script to understand where the problem comes from.
Your suggestions about how to bring this project to a safe shore are very welcome. So, any good plugins or 3rd party app to monitor the data and facilitate my implementation can help.
We are an outlier there. We are using the OCX and connect to it in winforms.
We have then standard c# code with everything debuggable and it makes everyone here very happy indead after using endless amount of time debugging javascripts.
The users use QV for selecting stuff and then we use the selected event in the OCX and pull the selected data from QV for postprocessing and tag the QV data with dynamic sql update.
I do not nessesarily recommend this method, but it has increased dramatically the development output for us when using QV for datamining and then processing the data selected.
Next project we are not going to use the OCX. But all the buisness logic and postprocessing is in a com visible c# dll' that we access through vbscript macro.
EDIT. More details
This is the current setup communicating with the document through OCX
Change a selection
axQlikMainApp.ActiveDocument.Fields("%UnitID").Clear();
var selSuccess = axQlikMainApp.ActiveDocument.Fields(cls.QlikView.QvEvalStr.Fields.UnitId).Select("(%UnitID)");
reset a sheet object
axQlikMainApp.ActiveDocument.ClearCache();
axQlikMainApp.ActiveDocument.GetSheetObject("Document\\MySheetObjectName").Restore();
get a string from QV
string res axQlikMainApp.ActiveDocument.Evaluate("=concat(Distinct myField1 &'|' & MyField2,'*')");
and can get horribly complicated
string res axQlikMainApp.ActiveDocument.Evaluate( "=MaxString({1 <%UnitID= {" + sUnitIds + #"}>}'<b>' & UnitName & '</b> \r\n bla bla bla:' & UnitNotesPlanning) & " +
"'\n title1: ' & Count({1 <%UnitID= {" + sUnitIds +#"},%ISODate={'" + qlickViewIsoDate + "'},Need = {'Ja'}" + MinusCalc + ">}Distinct %CivicRegNo) & " +
"'\n Title2: ' & Count({1 <%UnitID= {" + sUnitIds + #"},%ISODate={'" + qlickViewIsoDate + "'} " + recallMinusCalc + ">}DISTINCT RevGUID) & " +
"'\n Title3: ' & Count({1 <%UnitID= {" + sUnitIds + #"},%ISODate={'" + qlickViewIsoDate + "'},Need2 = {'Ja'}>}Distinct %CivicRegNo) & '" +
"\n Title4:' & MinString({1 <%UnitID= {" + sUnitIds + #"},FutureBooking = {1}>} Date(BookingStart) & ' Beh: ' & If(IsNull(ResourceDisplayedName),'_',ResourceDisplayedName)) &'" +
"\n Title5:' & MaxString({1 <%UnitID= {" + sUnitIds + #"},FutureBooking = {0}>} Date(BookingStart) & ' Beh: ' & If(IsNull(ResourceDisplayedName),'_',ResourceDisplayedName)) &''" +
" & MaxString({1 <%UnitID= {" + sUnitIds + #"}>}if(UnitGeo_isRelocatedOnSameGeo=1,'\nOBS! Multiple geo addresses. Zoom!',''))" +
""
);

ASP Classic My company has a homegrown app that has issues since a move to Server 2008

We have an intranet app that basically queries a bunch of databases and arranges the data. It is written in ASP(I KNOW) and upon a move to Windows Server 2008 we have one field that no longer populates. I know the database connection is good as everything else on that page loads just fine. This leads me to believe that it is a problem with the syntax of that particular query and that since it is using TO_DATE maybe there is some difference between Server 2003 and 2008 in regards to date format.
'SQL TO PULL PROCESS GROUP
pgsql = "SELECT DISTINCT subsystem_process_group.subsystem_id, subsystem_process_group.process_group_id, "
pgsql = pgsql & "process_group.process_group_name, oncall_group_day.employee_nbr "
pgsql = pgsql & " FROM eco_admin.process_group, eco_admin.subsystem_process_group, eco_admin.oncall_group_day "
pgsql = pgsql & "WHERE ((process_group.process_group_id = subsystem_process_group.process_group_id) "
pgsql = pgsql & "AND (process_group.process_group_id = oncall_group_day.process_group_id(+)) "
pgsql = pgsql & "AND (ONCALL_GROUP_DAY.CALENDAR_DATE(+) = TO_DATE(SYSDATE)) "
pgsql = pgsql & "AND (oncall_group_day.oncall_member_role_code(+) = 'P" & hour(now) & "') "
pgsql = pgsql & "AND (subsystem_process_group.subsystem_id = " & request("id") & ")) "
function get_name(emp_nbr)
sql3 = "select LTRIM(RTRIM(INITCAP(COMMON_NAME))) COMMON_NAME, LTRIM(RTRIM(INITCAP(LAST_NAME))) last_name from (select EMPLOYEE_NBR,COMMON_NAME, LAST_NAME from hrit_admin.employee union all select CONTRACT_RESOURCE_ID, COMMON_NAME, LAST_NAME from hrit_admin.contract_resource) a where employee_nbr = a.employee_nbr and employee_nbr = " & emp_nbr
rs3.open sql3,conn
get_name = rs3("COMMON_NAME") & " " & rs3("LAST_NAME")
rs3.close
end function

Issue using Oracle date function with Spring's NamedParamenterJdbcTemplate

I'm having an issue trying to get my SQL query which works fine in SQL Developer (Oracles free database tool) to also work using Spring's NamedParameterJdbcTemplate class.
My query is:
String sql = " SELECT COUNT(*) FROM ( " +
" SELECT FE.USR_ID, MAX(FE.DATE_FIRST_SUB) AS SUB_DATE " +
" FROM FC, FE " +
" WHERE FC_STATUS = 'MEMBER' " +
" AND FC.FC_SPC_ID = :spcId " +
" AND FE.FE_USR_ID = FC.FC_USR_ID " +
" AND FE.DATE_FIRST_SUB IS NOT NULL " +
" GROUP BY FE_USR_ID " +
" ) " +
" WHERE SUB_DATE BETWEEN TO_DATE('01-JUN-2011', 'DD-MON-YYYY') AND TO_DATE('01-JUL-2011', 'DD-MON-YYYY') ";
It has something to do with my dates, formatting perhaps? When I don't use the WHERE clause in the outer select it works, when it's included 0 is returned from the count - as I mentioned running the SQL directly returns expected results.
Any advice?
Thanks.
Oh my, I was in fact looking at the wrong database!!

Resources