FROM apps.ap_suppliers aps ,
apps.ap_invoices_all ai ,
apps.ap_invoice_lines_all ail ,
apps.ap_invoice_distributions_all aid,
apps.AP_DISTRIBUTION_SETS_all ads ,
apps.gl_code_combinations_kfv gcc ,
apps.ap_checks_all aca ,
apps.ap_invoice_payments_all aipa ,
apps.FND_TERRITORIES_TL ft
WHERE aps.vendor_id = ai.vendor_id
AND ai.invoice_id = ail.invoice_id
AND ai.invoice_id = aid.invoice_id
AND ail.invoice_id = aid.invoice_id
AND ai.DISTRIBUTION_SET_ID = ads.DISTRIBUTION_SET_ID(+)
AND aid.dist_code_combination_id = gcc.code_combination_id
AND aca.check_id = aipa.check_id
AND aipa.invoice_id = ai.invoice_id
AND aca.vendor_id = aps.vendor_id
AND aca.vendor_id = ai.vendor_id
AND aca.COUNTRY = ft.TERRITORY_CODE
AND ai.invoice_id =nvl(p_invoice_id,ai.invoice_id)
AND ai.last_update_date BETWEEN NVL(p_from_date,ai.last_update_date)
AND NVL(p_to_date,sysdate+1);
last_update_date having the date like 11-JUN-16,
so am passing the same.
Query is failing at date parameter level(Data types are p_from_date Date,p_to_date Date). Query returning no result
last_update_date is a date. The data is not held as 11-JUN-16, it's held as a date. When you pass in a string like '11-JUN-16' that might well be interpreted as 11/06/0016. You won't have any invoices that old and that may well be why your query returns no data.
Always state the format when converting strings to dates. And why not always use a four-digit year just to avoid ambiguity. And finally use a numeric month - that way language is not an issue :
TO_DATE('11/06/2016','DD/MM/YYYY')
Related
I'm looking at doing some report development for one of our Training softwares. I finally got some queries working in FB Maestro, as I'm only familiar with SQL and Oracle.
I have the following query that works and returns results, but when trying to set up a parameter for the display name, the query runs (at least it returns no errors) however the dataset does not return any data. Has anyone worked with these before?
Here's the query:
Select CertStatus, DisplayName, Count(CertStatus) From ( With cte as (Select * From (Select COURSEVERSIONSWITHAGGREGATES.CourseTitle, COURSEVERSIONSWITHAGGREGATES.CourseNumber, "MaxTrainedCompletionDate", "Course_ID", PersonnelView.DISPLAYNAME, COURSEVERSIONSWITHAGGREGATES.RecertificationValue, COURSEVERSIONSWITHAGGREGATES.RECERTIFICATIONUNIT_ID,
CASE
WHEN COURSEVERSIONSWITHAGGREGATES.RECERTIFICATIONUNIT_ID = 3 THEN DATEADD(year, 1*COURSEVERSIONSWITHAGGREGATES.RECERTIFICATIONVALUE, MaxTrainingView."MaxTrainedCompletionDate")
WHEN COURSEVERSIONSWITHAGGREGATES.RECERTIFICATIONUNIT_ID = 2 THEN DATEADD(month, 1*COURSEVERSIONSWITHAGGREGATES.RECERTIFICATIONVALUE, MaxTrainingView."MaxTrainedCompletionDate")
WHEN COURSEVERSIONSWITHAGGREGATES.RECERTIFICATIONUNIT_ID = 1 THEN DATEADD(week, 1*COURSEVERSIONSWITHAGGREGATES.RECERTIFICATIONVALUE, MaxTrainingView."MaxTrainedCompletionDate")
WHEN COURSEVERSIONSWITHAGGREGATES.RECERTIFICATIONUNIT_ID = 0 THEN DATEADD(day, 1*COURSEVERSIONSWITHAGGREGATES.RECERTIFICATIONVALUE, MaxTrainingView."MaxTrainedCompletionDate") END
AS ExpirationDate
From MAXTRAININGVIEW
INNER JOIN PERSONNELVIEW ON (MAXTRAININGVIEW."Personnel_ID" = PERSONNELVIEW.PERSONNELID) INNER JOIN COURSEVERSIONSWITHAGGREGATES ON (MAXTRAININGVIEW."Course_ID" = COURSEVERSIONSWITHAGGREGATES.COURSEID)
WHERE Personnelview.DisplayName = 'Aaron')) Select CourseTitle, CourseNumber, "MaxTrainedCompletionDate", "Course_ID", DisplayName, RecertificationValue, Recertificationunit_ID, ExpirationDate,
CASE WHEN ExpirationDate > current_date Then 'Active' WHEN ExpirationDate < current_date Then 'Expired' END As CertStatus from cte) Group By CertStatus, DisplayName
This returns values with the static value of 'Aaron' in report builder. But trying to use a parameter, it does not throw an error in report builder, however it just does not return any data.
For example this:
WHERE Personnelview.DisplayName = '#DisplayName'))
I've got the parameter based off another data set query, and that seems to work (it gives me the option to select employees)
Here is an example of it passing 'Aaron' (with personal info removed)
Example of passing #FName Parameter:
If you want to pass the parameter in report, other type database might not recognize query like "where [field] in #parameter", so I think you could try to use filter to achieve this goal(create a filter in dataset, and create a parameter, then specify it in filter properties).
I would like to know if it is possible to perform an SQL query and pass it a numerical parameter. Let's suppose that I have the following query:
SELECT
CONCAT(cuatrimestre,' Cuatrimestre') As quarter
, ROUND(SUM(fact_Ventas.cantidad * precioUnitario),0) as amount
FROM fact_Ventas
INNER JOIN dim_Tiempos ON
fact_Ventas.idAnio = dim_Tiempos.idAnio AND
fact_Ventas.idMes = dim_Tiempos.idMes AND
fact_Ventas.idDia = dim_Tiempos.idDia
INNER JOIN dim_Clientes ON dim_Clientes.idCliente = fact_Ventas.idCliente
INNER JOIN dim_Productos ON dim_Productos.idProducto = fact_Ventas.idProducto
WHERE
CAST(fact_Ventas.idAnio As Char) LIKE ${paramAnio} AND
CAST(fact_Ventas.idMes As Char) LIKE ${paramMes} AND
CAST(fact_Ventas.idVendedor As Char) LIKE ${paramVendedores} AND
CAST(fact_Ventas.origen As Char) LIKE ${paramOrigen} AND
dim_Productos.marca LIKE ${paramMarca} AND
dim_Clientes.segmentoCliente LIKE ${paramSegmento}
GROUP BY 1
ORDER BY 1
I want to divide the column amount, by a numerical value extracted from a simple parameter. I managed to use filters in the where clause, but I can not make a division in a column.
Try the following query:
SELECT
CONCAT(cuatrimestre,' Cuatrimestre') As cuatrimestre
, ROUND( (SUM(fact_Ventas.cantidad * precioUnitario)/${paramValue}),0) as Importe
FROM fact_Ventas
INNER JOIN dim_Tiempos ON
fact_Ventas.idAnio = dim_Tiempos.idAnio AND
fact_Ventas.idMes = dim_Tiempos.idMes AND
fact_Ventas.idDia = dim_Tiempos.idDia
INNER JOIN dim_Clientes ON dim_Clientes.idCliente = fact_Ventas.idCliente
INNER JOIN dim_Productos ON dim_Productos.idProducto = fact_Ventas.idProducto
WHERE
CAST(fact_Ventas.idAnio As Char) LIKE ${paramAnio} AND
CAST(fact_Ventas.idMes As Char) LIKE ${paramMes} AND
CAST(fact_Ventas.idVendedor As Char) LIKE ${paramVendedores} AND
CAST(fact_Ventas.origen As Char) LIKE ${paramOrigen} AND
dim_Productos.marca LIKE ${paramMarca} AND
dim_Clientes.segmentoCliente LIKE ${paramSegmento}
GROUP BY 1
ORDER BY 1
But it gives an error and the data is not loaded. The syntax of the query was tested in the database and is correct.
Did you set the parameter type to Numeric? It defaults to String which was probably fine for your other parameters.
The problem was that I forgot to assign the parameter to the component, I had associated it with SQL Query but not with the component.
I need to convert MSSQL query to Oracle but end up with SQL command not properly ended.
Here is MSSQL query
SELECT * FROM [dbo].[trade] AS [Extent1]
WHERE EXISTS (
SELECT 1 AS [C1] FROM
[dbo].[findetail] AS [Extent2]
INNER JOIN [dbo].[transact] AS [Extent3] ON [Extent2].[transact] = [Extent3].[transact]
WHERE [Extent1].[trade] = [Extent2].[trade]
AND 'ACCR' = [Extent3].[subledger]
AND [Extent3].[date] = '2016-03-18T00:00:00'
)
Converting it to Oracle SQL I end with this.
SELECT * FROM trade Extent1
WHERE EXISTS
(SELECT 1 C1 FROM findetail Extent2
JOIN transact Extent3
ON Extent2.transact=Extent3.transact
WHERE Extent1.trade=Extent2.trade
AND 'ACCR'=Extent3.subledger
AND Extent3.date='2016-03-18T00:00:00'
);
and receive error above.
Date formats are different in Oracle. Perhaps something like this:
SELECT *
FROM trade Extent1
WHERE EXISTS (SELECT 1
FROM findetail Extent2 JOIN
transact Extent3
ON Extent2.transact = Extent3.transact
WHERE Extent1.trade = Extent2.trade AND
Extent3.subledger = 'ACCR' AND
Extent3."date" = DATE '2016-03-18'
);
DATE is a reserved word so needs to the surrounded in double quotes and, I am assuming that it is of DATE data type so you will probably need to convert the string:
SELECT *
FROM trade t
WHERE EXISTS (
SELECT 1
FROM findetail f
JOIN transact r
ON f.transact = r.transact
WHERE t.trade = f.trade
AND 'ACCR' = r.subledger
AND r."DATE" = TO_DATE( '2016-03-18T00:00:00', 'YYYY-MM-DD"T"HH24:MI:SS' )
);
If you just use the string in r."DATE" = '2016-03-18T00:00:00' then Oracle will implicitly try to convert the string literal using the TO_DATE() function with the NLS_DATE_FORMAT session parameter as the format mask. If they match then it will work but this is a client variable so can be changed and then the query will break without the code having changed (and be a pain to debug). The simple answer is to ensure that you compare date value by either using TO_DATE() and specifying the format mask (as per the query above) or to use an ANSI date literal DATE '2016-03-18' (which is independent of the NLS settings).
I am having trouble with the final piece of my append query. I have the records generating just like I want with the exception of not triggering until the Expression Event Date is <=Date(). It is giving me a unmatched error when I place the <=Date() in the criteria field of the query builder. I tried it with DateSerial and a few other variations. I'm sure it has to do with the expression being that and not a hard date. Any assistance would be appreciated.
INSERT INTO SchedulingLog (
UserID
, LogDate
, EventDate
, Category
, CatDetail
, [Value]
)
SELECT Roster.UserID
, Date() AS LogDate
, DateSerial(Year(Date()),Month([WM DOH]),Day([WM DOH])) AS EventDate
, SchedulingLog.Category
, SchedulingLog.CatDetail
, Max(tblAccrual!WeeksAccrual*Roster!Schedule) AS [Value]
FROM tblAccrual
, [Schedule Type]
, Category
INNER JOIN CatDetail
ON Category.CategoryID = CatDetail.CategoryID
, SchedulingLog
INNER JOIN Roster
ON SchedulingLog.UserID = Roster.UserID
WHERE (((tblAccrual.Years)<=Round((Date()-[wm doh])/365,2)))
GROUP BY Roster.UserID
, Date()
, DateSerial(Year(Date()),Month([WM DOH]),Day([WM DOH]))
, SchedulingLog.Category
, SchedulingLog.CatDetail
HAVING (((SchedulingLog.Category) Like "Vac*")
AND ((SchedulingLog.CatDetail) Like "Ann*"));
I believe the issue is not explicitly converting the user input date with CDate. I suspect it's fine in most of the query because the [MW DOH] parameter is provided directly to functions which will convert it to date. However the WHERE clause would need an explicit conversion.
The following generates the error "This expression is typed incorrectly, or it is too complex to be evaluated. For example, a numeric expression may contain too many complicated elements. Try simplifying the expression by assigning parts of the expression to the variables."
SELECT Date()-[userinput] AS something;
Whereas the following code does not
SELECT Date()-CDate([userinput]) AS something;
I have a report that I am trying to fix with SSRS because when you run it for a specific range say one month of year. It will give you all previous years too even if its outside of parameter bounds.
SELECT
to_char(app.RECEIVED_DATE, 'mm-dd-yyyy') AS received_date
, res.RESIDENCETYPE_NAME || ' - ' || act.ACTIONTYPE_NAME type
, sts.APPLSTSTYPE_NAME AS Status
, COUNT(*) AS Total_Count
FROM
ODILIC_ADMIN.LICENSEAPPL app
, ODILIC_ADMIN.LICENSEDEF def
, ODILIC_ADMIN.ACTIONTYPE act
, ODILIC_ADMIN.APPLSOURCE src
, ODILIC_ADMIN.RESIDENCETYPE res
, ODILIC_ADMIN.LICENSETYPE ltype
, ODILIC_ADMIN.LICENSINGENTITYTYPE etype
, ODILIC_ADMIN.APPLSTSTYPE sts
WHERE app.LICENSEDEF_ID = def.LICENSEDEF_ID
AND app.ACTIONTYPE_ID = act.ACTIONTYPE_ID
AND app.APPLSOURCE_ID = src.APPLSOURCE_ID
AND def.RESIDENCETYPE_ID = res.RESIDENCETYPE_ID
AND def.LICENSETYPE_ID = ltype.LICENSETYPE_ID
AND def.LICENSINGENTITYTYPE_ID = etype.LICENSINGENTITYTYPE_ID
AND app.APPLSTSTYPE_ID = sts.APPLSTSTYPE_ID
AND (app.RECEIVED_DATE BETWEEN '01-JUN-2013' AND '30-JUN-2013')
and sts.APPLSTSTYPE_NAME in ('Completed')
GROUP BY
to_char(app.RECEIVED_DATE, 'mm-dd-yyyy')
, res.RESIDENCETYPE_NAME
, act.ACTIONTYPE_NAME
, sts.APPLSTSTYPE_NAME
order by 1
So this query will filter between jun 1 and jun 30 of this year. When I run it in plsql it works fine but as soon as I put it into ssrs it will give me june counts for 2012 and 2011
On this line: AND (app.RECEIVED_DATE BETWEEN '01-JUN-2013' AND '30-JUN-2013')
I would be setting up parameters in SSRS directly to handle this as this may handle the translation of types more expicitly to specify (DateTime) as the parameter type and then changing the line to be:
AND (app.RECEIVED_DATE BETWEEN #Start AND #End)
I have not played with plsql with SSRS but I have seen translation of types problems with dealing with WCF and other channels. My usual attempt is to first specify a parameter to pass into the query execution and see if there is still an issue.