Query with dynamic variables and customised caption
How to change the Field label when the query asking dynamic values during the execution?
for example: in where condition i want to give a country name during the query execution, but in the small window it will display as 'Name' which is a country name. i want to display it as 'Country Name' which should be more readable for the end user. How can we achieve this?
Thanks
SV Reddy
Hi,
Unfortunately, it is not possible to change the system field description.
Refer to this thread
Re: Parameter Display Name Reg.
Regards,
Vijay Kumar
SAP Business One Forums Team
Similar Messages
-
Absolute dynamic select query with dynamic join and where
Has anyone ever tried creating an absolutely dynamic SELECT query with dynamic Join and Where conditions.
I have a requirement of creating such a query in an Utility Class, and i have written the code. But its throwing my sysntax errors.
Please let me know where am I going wrong OR is it really possible to create such a dynamic Query??
SELECT (FIELDS) INTO TABLE IT_TABLES
FROM ( (ME->TABLE1) inner join ( me->table2 )
on ( on_condition ) )
WHERE (me->where_fields).
Ags.It worked for me in a following way:
select * into corresponding fields of table <result_table>
from (join_string)
where (l_where).
Where the contents of join_string were dynamically build using concatenation. So it will be something like
concatenate ME->TABLE1 'as a INNER JOIN' me->table2 'as b ON (' into join_string separated by space.
<...>
add here matching/reference colums, something like
concatenate 'a~' me->TABLE1_JOIN_COL into temp1.
concatenate 'b~' me->TABLE2_JOIN_COL into temp2.
concatenate join_string temp1 '=' temp2 into join_string separated by space.
<...>
concatenate join_string ')' into join_string separated by space.
And then use similar approach for l_where variable. -
Af:query with bind variables and Saved Search
I have a VO and view criteria(VC).
VC has a criteria item ObsoleteDate with range specified as bindVariables "dateFrm" and "dateTo" I dragged & dropped the named criteria as af:Query with table. Table toolbar has 2 buttons in which I set & clear the bind variables. Data is fetched as per as expected based on the VC & bind variables.
The problem is,
If I save my search with bind variables set and swap between the saved searches , all works fine. But the moment I clear bind variables & swap between searches.. "dateFrm" is populated and "dateTo" is null and I get an Exception oracle.jbo.AttrValException: JBO-27035: Attribute Obsolete Date: is required.
Why is this happening?? Saved search is supposed to save the VC with all the bind values set while saving and clearing bind variables shouldn't affect the saved search, right?? Or I have understood it wrong?
I am using JDeveloper 11.1.2.3.0
ThanksTry
like ? || '%' -
BW-Query with hierarchy variable and webi-prompt
Hi,
I think I've got a quite simple question.
I've got a SAP-BW-Query and a hierarchy variable, and some none hierarchy variables.
All Variables work in the webi-prompt.
For the none hierarchy variables I've got the chance to search for values in the LOV, but I can't search for
values in the hierarchies.Can I enable this function to search?
Kind regards
LarsHi
I post the error once again. I made an easier query and i saw that last time the forum did some strange things.
A database error occured. The database error text is: Die MDX-Abfrage
SELECT { [Measures].[DC59N8GR349ETCCV3ZHIFFWGC] } ON COLUMNS
FROM [ZTESTM01/Z_ZTESTM01_TEST5_VARIABLE]
SAP VARIABLES [!V000002] INCLUDING [0FISCPER].[V62009001]
konnte nicht ausgeführt werden. Fehler Specify a value for variable
MMEP_FISCPER. (WIS 10901)
The query runs perfect in RSRT.
When i put the statement
SELECT
{ [Measures].[DC59N8GR349ETCCV3ZHIFFWGC] } ON COLUMNS
FROM [ZTESTM01/Z_ZTESTM01_TEST5_VARIABLE]
SAP VARIABLES [!V000002] INCLUDING [0FISCPER].[V62009001]
in MDXTEST, it gives a result.
Best regards,
Florian -
Query With Bind Variables and %
Hi,
Quick question. I am using ADF BC on Jdev 11 with a MySQL Database.
I've used Bind Variables in the past (I have to use a Question Mark [?]) and have had no problem.
Now I want to do something like this in my where clause:
SELECT TempTable.ABC FROM TempTable
WHERE ABC LIKE ?%
When I try and create the View Object with that query it is complaining about the %.
Am I required to append the % in my bind variable? Any examples I have seen of this, people are doing something like :p_id = 'Jo%'Try
like ? || '%' -
How to generate report with dynamic variable number of columns?
How to generate report with dynamic variable number of columns?
I need to generate a report with varying column names (state names) as follows:
SELECT AK, AL, AR,... FROM States ;
I get these column names from the result of another query.
In order to clarify my question, Please consider following table:
CREATE TABLE TIME_PERIODS (
PERIOD VARCHAR2 (50) PRIMARY KEY
CREATE TABLE STATE_INCOME (
NAME VARCHAR2 (2),
PERIOD VARCHAR2 (50) REFERENCES TIME_PERIODS (PERIOD) ,
INCOME NUMBER (12, 2)
I like to generate a report as follows:
AK CA DE FL ...
PERIOD1 1222.23 2423.20 232.33 345.21
PERIOD2
PERIOD3
Total 433242.23 56744.34 8872.21 2324.23 ...
The TIME_PERIODS.Period and State.Name could change dynamically.
So I can't specify the state name in Select query like
SELECT AK, AL, AR,... FROM
What is the best way to generate this report?SQL> -- test tables and test data:
SQL> CREATE TABLE states
2 (state VARCHAR2 (2))
3 /
Table created.
SQL> INSERT INTO states
2 VALUES ('AK')
3 /
1 row created.
SQL> INSERT INTO states
2 VALUES ('AL')
3 /
1 row created.
SQL> INSERT INTO states
2 VALUES ('AR')
3 /
1 row created.
SQL> INSERT INTO states
2 VALUES ('CA')
3 /
1 row created.
SQL> INSERT INTO states
2 VALUES ('DE')
3 /
1 row created.
SQL> INSERT INTO states
2 VALUES ('FL')
3 /
1 row created.
SQL> CREATE TABLE TIME_PERIODS
2 (PERIOD VARCHAR2 (50) PRIMARY KEY)
3 /
Table created.
SQL> INSERT INTO time_periods
2 VALUES ('PERIOD1')
3 /
1 row created.
SQL> INSERT INTO time_periods
2 VALUES ('PERIOD2')
3 /
1 row created.
SQL> INSERT INTO time_periods
2 VALUES ('PERIOD3')
3 /
1 row created.
SQL> INSERT INTO time_periods
2 VALUES ('PERIOD4')
3 /
1 row created.
SQL> CREATE TABLE STATE_INCOME
2 (NAME VARCHAR2 (2),
3 PERIOD VARCHAR2 (50) REFERENCES TIME_PERIODS (PERIOD),
4 INCOME NUMBER (12, 2))
5 /
Table created.
SQL> INSERT INTO state_income
2 VALUES ('AK', 'PERIOD1', 1222.23)
3 /
1 row created.
SQL> INSERT INTO state_income
2 VALUES ('CA', 'PERIOD1', 2423.20)
3 /
1 row created.
SQL> INSERT INTO state_income
2 VALUES ('DE', 'PERIOD1', 232.33)
3 /
1 row created.
SQL> INSERT INTO state_income
2 VALUES ('FL', 'PERIOD1', 345.21)
3 /
1 row created.
SQL> -- the basic query:
SQL> SELECT SUBSTR (time_periods.period, 1, 10) period,
2 SUM (DECODE (name, 'AK', income)) "AK",
3 SUM (DECODE (name, 'CA', income)) "CA",
4 SUM (DECODE (name, 'DE', income)) "DE",
5 SUM (DECODE (name, 'FL', income)) "FL"
6 FROM state_income, time_periods
7 WHERE time_periods.period = state_income.period (+)
8 AND time_periods.period IN ('PERIOD1','PERIOD2','PERIOD3')
9 GROUP BY ROLLUP (time_periods.period)
10 /
PERIOD AK CA DE FL
PERIOD1 1222.23 2423.2 232.33 345.21
PERIOD2
PERIOD3
1222.23 2423.2 232.33 345.21
SQL> -- package that dynamically executes the query
SQL> -- given variable numbers and values
SQL> -- of states and periods:
SQL> CREATE OR REPLACE PACKAGE package_name
2 AS
3 TYPE cursor_type IS REF CURSOR;
4 PROCEDURE procedure_name
5 (p_periods IN VARCHAR2,
6 p_states IN VARCHAR2,
7 cursor_name IN OUT cursor_type);
8 END package_name;
9 /
Package created.
SQL> CREATE OR REPLACE PACKAGE BODY package_name
2 AS
3 PROCEDURE procedure_name
4 (p_periods IN VARCHAR2,
5 p_states IN VARCHAR2,
6 cursor_name IN OUT cursor_type)
7 IS
8 v_periods VARCHAR2 (1000);
9 v_sql VARCHAR2 (4000);
10 v_states VARCHAR2 (1000) := p_states;
11 BEGIN
12 v_periods := REPLACE (p_periods, ',', ''',''');
13 v_sql := 'SELECT SUBSTR(time_periods.period,1,10) period';
14 WHILE LENGTH (v_states) > 1
15 LOOP
16 v_sql := v_sql
17 || ',SUM(DECODE(name,'''
18 || SUBSTR (v_states,1,2) || ''',income)) "' || SUBSTR (v_states,1,2)
19 || '"';
20 v_states := LTRIM (SUBSTR (v_states, 3), ',');
21 END LOOP;
22 v_sql := v_sql
23 || 'FROM state_income, time_periods
24 WHERE time_periods.period = state_income.period (+)
25 AND time_periods.period IN (''' || v_periods || ''')
26 GROUP BY ROLLUP (time_periods.period)';
27 OPEN cursor_name FOR v_sql;
28 END procedure_name;
29 END package_name;
30 /
Package body created.
SQL> -- sample executions from SQL:
SQL> VARIABLE g_ref REFCURSOR
SQL> EXEC package_name.procedure_name ('PERIOD1,PERIOD2,PERIOD3','AK,CA,DE,FL', :g_ref)
PL/SQL procedure successfully completed.
SQL> PRINT g_ref
PERIOD AK CA DE FL
PERIOD1 1222.23 2423.2 232.33 345.21
PERIOD2
PERIOD3
1222.23 2423.2 232.33 345.21
SQL> EXEC package_name.procedure_name ('PERIOD1,PERIOD2','AK,AL,AR', :g_ref)
PL/SQL procedure successfully completed.
SQL> PRINT g_ref
PERIOD AK AL AR
PERIOD1 1222.23
PERIOD2
1222.23
SQL> -- sample execution from PL/SQL block
SQL> -- using parameters derived from processing
SQL> -- cursors containing results of other queries:
SQL> DECLARE
2 CURSOR c_period
3 IS
4 SELECT period
5 FROM time_periods;
6 v_periods VARCHAR2 (1000);
7 v_delimiter VARCHAR2 (1) := NULL;
8 CURSOR c_states
9 IS
10 SELECT state
11 FROM states;
12 v_states VARCHAR2 (1000);
13 BEGIN
14 FOR r_period IN c_period
15 LOOP
16 v_periods := v_periods || v_delimiter || r_period.period;
17 v_delimiter := ',';
18 END LOOP;
19 v_delimiter := NULL;
20 FOR r_states IN c_states
21 LOOP
22 v_states := v_states || v_delimiter || r_states.state;
23 v_delimiter := ',';
24 END LOOP;
25 package_name.procedure_name (v_periods, v_states, :g_ref);
26 END;
27 /
PL/SQL procedure successfully completed.
SQL> PRINT g_ref
PERIOD AK AL AR CA DE FL
PERIOD1 1222.23 2423.2 232.33 345.21
PERIOD2
PERIOD3
PERIOD4
1222.23 2423.2 232.33 345.21 -
Creating Query with dynamic columns to show results
Hi experts,
I need to know how to create a query with dynamic columns. Meaning, I don't want to create a query with fixed columns representing the 12 periods of the fiscal year to show me actuals as the fiscal year proceeds.
For example, if I am currently in the middle of period 3 (March) of a fiscal year, when I execute the query, I need it to automatically only show me the 'Actuals' for periods 1 and 2, without seeing the columns from periods 3 to 12 showing blank.
Then when I am in the middle period 5 (May) the query should ONLY show me the columns for periods 1 to 4 'Actuals', no results should be shown for periods 5 to 12 yet, and I don't want to even see blank columns for period 6 to 12.
How do I define my columns, to achieve this.
Maximum points will be awarded.
Thanks Everyone.Hi Josh,
I'm having a little difficuluty understanding what should be included in my restricted key figures.
The time characteristics that I have available to use are:
0FISCPER3 (posting period)
0FISCYEAR (fiscal year), currently using SAP EXIT to default current fiscal year.
0FISCVARNT (fiscal year variant).
In addition, I have the following characteristics available to be used in the columns:
Value type (10)
version (currently I'm using variable for it)
Currency type (020)
Currency (USD).
Can you explain what my restricted key figure should be based on and how it should look.
I tried to create a restircted key figure using 0AMOUNT, and 0FISCPER3. For 0FISCPER3 I created a range from 1 to previous period (using SAP EXIT that supplied previous period).I also had value type, version, currency type, and currency included in that restricted key figure.Then when I tried to drag 0FISCPER3 under the restricted key figure once again, it wouldn't let me, probably because I've already used 0FISCPER3 in the restricted key figure.
Please let me know if my explanation is not clear.
Your step by step help would be great.
Thanks
Edited by: Ehab Mansour on Sep 23, 2008 2:40 PM -
From Clause query with form variables
forms 9.0.4 rdbms 9.2
Is it possible to create a From Clause query with form variables generated from another block (but in the same form)? I am not having any success.
I searched Metalink. It appears that according to DOC ID # 69884.1, in Forms 6i, this is not possible. Metalink suggest in DOC ID 104771.1 implementating a dynamic From Clause, but when I duplicate the example on my system, I receive an Oracle error. Further investigation from the web form (DISPLAY ERROR) indicates that the system does not see the dynamic value.
Has anyone else run into this error? Has this been fixed in forms 9.0.4 and I am just missing something? Does a dynamic from clause query work? Can anyone point me to an example or post an example or offer any advise.
thanks in advanceAs far as I know it is not possible to use block items in a from clause query in forms 9.0.4. Here is my solution for a From-Clause-Query via the 'Query-Data-Source-Name-Property':
To use the values of the block items in my from clause query I implemented a database package with getter and setter routines for the block item values I needed for the query.
In the Key-Exeqry-Trigger of the From-Clause-Query-Block I set the global package variables with values of the block-items I am interested in. In the From-Clause-Query I used the values in the where-clause via package functions which return the global package variables.
Hope my solution will work for your problem. -
Hello,
I would like to create a Dynamic SQL in which change is the name of the table according to the outcome of the first SQL. This is possible?
'WITH TABLE_X AS(SELECT LEVEL LVL FROM DUAL CONNECT BY LEVEL <= 12)' ||
'SELECT A.COL1, A.COL2, B.COL1, B.COL7' ||
' FROM TABLE_A' || TABLE_X.LVL || ' A' ||
' , TABLE_B' || TABLE_X.LVL || ' B' ||
' WHERE A.COL1 = B.COL1 AND ... 'tables in database
TABLE_A1
TABLE_A2
TABLE_A12
TABLE_B1
TABLE_B2
TABLE_B12let me know how I can do this
RegardsHi,
Sorry, I don't see what you're trying to do.
"Dynamic SQL" is really a mis-nomer. The number of tables and columns in a query, and their names, must be spelled out when the statement is compiled. There is nothing dynamic about it.
In dynamic SQL, a PL/SQL procedure or another query writes all or part of query just milliseconds before it is compiled, typically using data taken from tables or supplied by a user right then.
For example, consider this static query:
SELECT a.col1, a.col2, b.col1, b.col7
FROM table_1 a
, table_2 b
WHERE a.col1 = b.col1;Now, say the 1 in "table_1" and the 2 in "table_2" are variables, x and y, that you will want to look up from another table every time you run this query. You can make it dynamic like this:
sql_txt := 'SELECT a.col1, a.col2, b.col1, b.col7 '
|| 'FROM table_' || TO_CHAR (x) || ' a '
|| ', table_' || TO_CHAR (y) || ' b '
|| 'WHERE a.col_1 = b.col1';Now let's make it really interesting. Say that instead of 2 tables, and 1 join condition, you''ll have n tables and n-1 join conditions, where n has to be computed at (actually a split second before) run-time. That is, if n=4, you might need to construct a static query with 4 tables and 3 join conditions, like this:
SELECT a.col1, a.col2, b.col1, b.col7
FROM table_1 a
, table_2 b
, table_12 c
, table_2 d
WHERE a.col1 = b.col1
AND a.col1 = c.col1
AND a.col1 = d.col1;You can do that using dynamic SQL, too.
Post an example of the static query you need to build, and describe what parts of it are dynamic, and how you get the values for those parts, and someone will help you write the dynamic SQL. -
Query with bind variable, how can use it in managed bean ?
Hi
I create query with bind variable (BindControlTextValue), this query return description of value that i set in BindControlTextValue variable, how can i use this query in managed bean? I need to set this value in String parameter in managed bean.
ThanksPut the query in a VO and execute it the usual way.
If you need to, you can write a parameterized method in VOImpl that executes the VO query with the parameter and then call that method from the UI (as a methodAction binding) either through the managed bean or via a direct button click on the page. -
SQL query with Bind variable with slower execution plan
I have a 'normal' sql select-insert statement (not using bind variable) and it yields the following execution plan:-
Execution Plan
0 INSERT STATEMENT Optimizer=CHOOSE (Cost=7 Card=1 Bytes=148)
1 0 HASH JOIN (Cost=7 Card=1 Bytes=148)
2 1 TABLE ACCESS (BY INDEX ROWID) OF 'TABLEA' (Cost=4 Card=1 Bytes=100)
3 2 INDEX (RANGE SCAN) OF 'TABLEA_IDX_2' (NON-UNIQUE) (Cost=3 Card=1)
4 1 INDEX (FAST FULL SCAN) OF 'TABLEB_IDX_003' (NON-UNIQUE)
(Cost=2 Card=135 Bytes=6480)
Statistics
0 recursive calls
18 db block gets
15558 consistent gets
47 physical reads
9896 redo size
423 bytes sent via SQL*Net to client
1095 bytes received via SQL*Net from client
3 SQL*Net roundtrips to/from client
1 sorts (memory)
0 sorts (disk)
55 rows processed
I have the same query but instead running using bind variable (I test it with both oracle form and SQL*plus), it takes considerably longer with a different execution plan:-
Execution Plan
0 INSERT STATEMENT Optimizer=CHOOSE (Cost=407 Card=1 Bytes=148)
1 0 TABLE ACCESS (BY INDEX ROWID) OF 'TABLEA' (Cost=3 Card=1 Bytes=100)
2 1 NESTED LOOPS (Cost=407 Card=1 Bytes=148)
3 2 INDEX (FAST FULL SCAN) OF TABLEB_IDX_003' (NON-UNIQUE) (Cost=2 Card=135 Bytes=6480)
4 2 INDEX (RANGE SCAN) OF 'TABLEA_IDX_2' (NON-UNIQUE) (Cost=2 Card=1)
Statistics
0 recursive calls
12 db block gets
3003199 consistent gets
54 physical reads
9448 redo size
423 bytes sent via SQL*Net to client
1258 bytes received via SQL*Net from client
3 SQL*Net roundtrips to/from client
1 sorts (memory)
0 sorts (disk)
55 rows processed
TABLEA has around 3million record while TABLEB has 300 records. Is there anyway I can improve the speed of the sql query with bind variable? I have DBA Access to the database
Regards
IvanMany thanks for your reply.
I have run the statistic already for the both tableA and tableB as well all the indexes associated with both table (using dbms_stats, I am on 9i db ) but not the indexed columns.
for table I use:-
begin
dbms_stats.gather_table_stats(ownname=> 'IVAN', tabname=> 'TABLEA', partname=> NULL);
end;
for index I use:-
begin
dbms_stats.gather_index_stats(ownname=> 'IVAN', indname=> 'TABLEB_IDX_003', partname=> NULL);
end;
Is it possible to show me a sample of how to collect statisc for INDEX columns stats?
regards
Ivan -
Running a SQL Stored Procedure from Power Query with Dynamic Parameters
Hi,
I want to execute a stored procedure from Power Query with dynamic parameters.
In normal process, query will look like below in Power Query. Here the value 'Dileep' is passed as a parameter value to SP.
Source = Sql.Database("ABC-PC", "SAMPLEDB", [Query="EXEC DBO.spGetData 'Dileep'"]
Now I want to pass the value dynamically taking from excel sheet. I can get the required excel cell value in a variable but unable to pass it to query.
Name_Parameter = Excel.CurrentWorkbook(){[Name="Table3"]}[Content],
Name_Value = Name_Parameter{0}[Value],
I have tried like below but it is not working.
Source = Sql.Database("ABC-PC", "SAMPLEDB", [Query="EXEC DBO.spGetData Name_Value"]
Can anyone please help me with this issue.
Thanks
DileepHi,
I got it. Below is the correct syntax.
Source = Sql.Database("ABC-PC", "SAMPLEDB", [Query="EXEC DBO.spGetData '" & Name_Value & "'"]
Thanks
Dileep -
Dynamic select query with dynamic where condition
Hi all,
I want to use the dynamic select query with dynamic where condition. For that I used the below code but I am getting dump when using this code.
Please advice, if there is any other way to achieve this requirement.
Thanks,
Sanket Sethi
Code***************
PARAMETERS: p_tabnam TYPE tabname,
p_selfl1 TYPE edpline,
p_value TYPE edpline,
p_where1 TYPE edpline .
DATA: lt_where TYPE TABLE OF edpline,
lt_sel_list TYPE TABLE OF edpline,
l_wa_name TYPE string,
ls_where TYPE edpline,
l_having TYPE string,
dref TYPE REF TO data,
itab_type TYPE REF TO cl_abap_tabledescr,
struct_type TYPE REF TO cl_abap_structdescr,
elem_type TYPE REF TO cl_abap_elemdescr,
comp_tab TYPE cl_abap_structdescr=>component_table,
comp_fld TYPE cl_abap_structdescr=>component.
TYPES: f_count TYPE i.
FIELD-SYMBOLS : <lt_outtab> TYPE ANY TABLE,
* <ls_outtab> TYPE ANY,
<l_fld> TYPE ANY.
struct_type ?= cl_abap_typedescr=>describe_by_name( p_tabnam ).
elem_type ?= cl_abap_elemdescr=>describe_by_name( 'F_COUNT' ).
comp_tab = struct_type->get_components( ).
comp_fld-name = 'F_COUNT'.
comp_fld-type = elem_type.
APPEND comp_fld TO comp_tab.
struct_type = cl_abap_structdescr=>create( comp_tab ).
itab_type = cl_abap_tabledescr=>create( struct_type ).
l_wa_name = 'l_WA'.
CREATE DATA dref TYPE HANDLE itab_type.
ASSIGN dref->* TO <lt_outtab>.
*CREATE DATA dref TYPE HANDLE struct_type.
*ASSIGN dref->* TO <ls_outtab>.
* Creation of the selection fields
APPEND p_selfl1 TO lt_sel_list.
APPEND 'COUNT(*) AS F_COUNT' TO lt_sel_list.
** Creation of the "where" clause
*CONCATENATE p_selfl1 '= '' p_value ''.'
* INTO ls_where
* SEPARATED BY space.
*APPEND ls_where TO lt_where.
* Creation of the "where" clause
APPEND p_where1 TO lt_where.
* Creation of the "having" clause
l_having = 'count(*) >= 1'.
* THE dynamic select
SELECT (lt_sel_list)
FROM (p_tabnam)
INTO CORRESPONDING FIELDS OF TABLE <lt_outtab>.
* WHERE (lt_where).Hi Sanket,
The above given logic of mine works for you, put the code in the If condition and try-
just like below:
IF NOT P_EBELN IS INITIAL.
lt_where = '& = ''&'' '.
REPLACE '&' WITH p_ebeln INTO lt_where.
REPLACE '&' WITH field_value INTO lt_where.
SELECT (lt_sel_list) INTO CORRESPONDING FIELDS OF TABLE <lt_outtab>
FROM (p_tabnam)
WHERE (lt_where).
ENDIF.
thanks\
Mahesh -
I have a query with two variables (Employee and Date). The query is working fine if both of the variables are check and values assigned. But if only one variable is checked and a value assigned then the query will return 0 results. Is it possible that the query cannot work with only one variable out of the 2? Do I need a workaround or am i doing something wrong?
Here is the query:
SELECT T0.DocNum, T0.DocDate, T0.DocDueDate, T0.CardCode, T0.CardName, T0.Address, T0.DocTotal, T0.U_Employee, T1.firstName,T1.lastName, T0.Comments FROM OVPM T0 LEFT JOIN OHEM T1 ON T0.U_EMPLOYEE = T1.FIRSTNAME' 'T1.LASTNAME WHERE T0.DocType = 'A' AND T0.U_EMPLOYEE = [%0] AND T0.DocDate =[%1].
Thank you so much for your help,
Irina StancaAFAIK, at least with 'complex queries' unchecked parameter gets
some default/blank value. Therefore, you should allow default values in your
WHERE clause.
You want: WHERE T0.COL = @VAR
You write: WHERE (T0.COL = @VAR OR [logical test for @VAR is a default value])
Snippets like this may help you in finding out that default value:
-- snip --
/SELECT FROM [dbo].[OHEM] T9/
declare @VAR_EMPL as char(20)
/* WHERE */
set @VAR_EMPL = /* T9.lastName */ '[%0]'
/SELECT FROM [dbo].[OVPM] T8/
declare @VAR_DATE as char(20)
/* WHERE */
set @VAR_DATE = /* T8.DocDate */ '[%1]'
SELECT '@VAR_EMPL: ' + '|' + @VAR_EMPL + '|' + '@VAR_DATE: ' + @VAR_DATE + ' DATEDIFF: ' + cast(DATEDIFF(day, CAST('1900-01-01' as datetime), CAST(@VAR_DATE as datetime)) as varchar)
[/code]
-- snip --
Yes, it looks like the default value for dates is '1900-01-01'.
Therefore, you may want to code this way
.. WHERE (DocDate = @VAR_DATE OR DATEDIFF(day, CAST('1900-01-01' as datetime), CAST(@VAR_DATE as datetime)) > 0)
I also noticed a date-related issue that may cause problems in complex queries
if you work with dates from last century AND if your date format in B1 is YY instead of CCYY:
you enter 1907 and B1 interprets it as 2007.
HTH
Juha -
How do I create a folder or report from a query with a union and parameters
I have created folders with unions but I am having difficulty coverting a query with a union and parameters.
The following works great in SQL*Developer without parameters, but I want to change to use parameters for the year and quarter and use it in Discoverer:
SELECT TO_CHAR(NVL(AV.TAX_ID,999999999),'000000000') FEID,
AV.FIRM_NAME VENDOR_NAME,
AV.BIDCLASS CONTRACT_CODES,
AV.AWAMT AWARD_AMOUNT,
AV.SOL_MODE FORMAL_INFORMAL,
AV.CERT BUSINESS_ENTITY,
AV.ETHNICITY ETHNICTY,
AV.PO_NUMBER_FORMAT CONTRACT,
SUM(VP.INVOICE_AMOUNT) AMOUNT_PAID_$
FROM CONFIRM.VSTATE_PAID_AWARD_VENDORS AV,
CONFIRM.VSTATE_VENDOR_PAYMENTS VP
WHERE ( ( AV.PO_NUMBER = VP.PO_NUMBER
AND AV.VENDOR_ID = VP.VENDOR_ID ) )
AND (TO_CHAR(VP.PAYMENT_DATE,'Q') = '4')
AND ( TO_CHAR(VP.PAYMENT_DATE,'YYYY') = '2009' )
GROUP BY TO_CHAR(NVL(AV.TAX_ID,999999999),'000000000'),
AV.FIRM_NAME,
AV.BIDCLASS,
AV.AWAMT,
AV.SOL_MODE,
AV.CERT,
AV.ETHNICITY,
AV.PO_NUMBER_FORMAT
union
SELECT TO_CHAR(NVL(AV2.TAX_ID,999999999),'000000000') FEID,
AV2.FIRM_NAME VENDOR_NAME,
AV2.BIDCLASS CONTRACT_CODES,
AV2.AWAMT AWARD_AMOUNT,
AV2.SOL_MODE FORMAL_INFORMAL,
AV2.CERT BUSINESS_ENTITY,
AV2.ETHNICITY ETHNICTY,
AV2.PO_NUMBER_FORMAT CONTRACT,
0 AMOUNT_PAID_$
FROM CONFIRM.VSTATE_PAID_AWARD_VENDORS AV2
WHERE
not exists (SELECT 'X'
FROM CONFIRM.VSTATE_VENDOR_PAYMENTS VP2
WHERE av2.po_number = vp2.po_number
AND (TO_CHAR(VP2.PAYMENT_DATE,'Q') = '4')
AND ( TO_CHAR(VP2.PAYMENT_DATE,'YYYY') = '2009' ))
AND (TO_CHAR(AV2.AWDATE,'Q') = '4')
AND (to_CHAR(AV2.AWDATE,'YYYY') = '2009')
GROUP BY TO_CHAR(NVL(AV2.TAX_ID,999999999),'000000000'),
AV2.FIRM_NAME,
AV2.BIDCLASS,
AV2.AWAMT,
AV2.SOL_MODE,
AV2.CERT,
AV2.ETHNICITY,
AV2.PO_NUMBER_FORMAT Can someone provide a solution?
Thank you,
RobertHi,
You can take the parameters to the select so that you will be able to create conditions over them.
Try to use this SQL instead of your and in the discoverer workbook create the conditions and parameters:
SELECT TO_CHAR(NVL(AV.TAX_ID,999999999),'000000000') FEID,
AV.FIRM_NAME VENDOR_NAME,
AV.BIDCLASS CONTRACT_CODES,
AV.AWAMT AWARD_AMOUNT,
AV.SOL_MODE FORMAL_INFORMAL,
AV.CERT BUSINESS_ENTITY,
AV.ETHNICITY ETHNICTY,
AV.PO_NUMBER_FORMAT CONTRACT,
TO_CHAR(VP.PAYMENT_DATE,'YYYY') P_YEAR,
TO_CHAR(VP.PAYMENT_DATE,'Q') P_QTR
SUM(VP.INVOICE_AMOUNT) AMOUNT_PAID_$
FROM CONFIRM.VSTATE_PAID_AWARD_VENDORS AV,
CONFIRM.VSTATE_VENDOR_PAYMENTS VP
WHERE ( ( AV.PO_NUMBER = VP.PO_NUMBER
AND AV.VENDOR_ID = VP.VENDOR_ID ) )
--AND (TO_CHAR(VP.PAYMENT_DATE,'Q') = '4')*
--AND ( TO_CHAR(VP.PAYMENT_DATE,'YYYY') = '2009' )*
GROUP BY TO_CHAR(NVL(AV.TAX_ID,999999999),'000000000'),
AV.FIRM_NAME,
AV.BIDCLASS,
AV.AWAMT,
AV.SOL_MODE,
AV.CERT,
AV.ETHNICITY,
AV.PO_NUMBER_FORMAT ,
TO_CHAR(VP.PAYMENT_DATE,'YYYY') P_YEAR,
TO_CHAR(VP.PAYMENT_DATE,'Q') P_QTR
union
SELECT TO_CHAR(NVL(AV2.TAX_ID,999999999),'000000000') FEID,
AV2.FIRM_NAME VENDOR_NAME,
AV2.BIDCLASS CONTRACT_CODES,
AV2.AWAMT AWARD_AMOUNT,
AV2.SOL_MODE FORMAL_INFORMAL,
AV2.CERT BUSINESS_ENTITY,
AV2.ETHNICITY ETHNICTY,
AV2.PO_NUMBER_FORMAT CONTRACT,
TO_CHAR(VP.PAYMENT_DATE,'YYYY') P_YEAR,
TO_CHAR(VP.PAYMENT_DATE,'Q') P_QTR
0 AMOUNT_PAID_$
FROM CONFIRM.VSTATE_PAID_AWARD_VENDORS AV2
WHERE
not exists (SELECT 'X'
FROM CONFIRM.VSTATE_VENDOR_PAYMENTS VP2
WHERE av2.po_number = vp2.po_number
AND (TO_CHAR(VP2.PAYMENT_DATE,'Q') = TO_CHAR(VP.PAYMENT_DATE,'Q') )
AND ( TO_CHAR(VP2.PAYMENT_DATE,'YYYY') = TO_CHAR(VP.PAYMENT_DATE,'YYYY') ))
--AND (TO_CHAR(AV2.AWDATE,'Q') = '4')*
--AND (to_CHAR(AV2.AWDATE,'YYYY') = '2009')*
GROUP BY TO_CHAR(NVL(AV2.TAX_ID,999999999),'000000000'),
AV2.FIRM_NAME,
AV2.BIDCLASS,
AV2.AWAMT,
AV2.SOL_MODE,
AV2.CERT,
AV2.ETHNICITY,
AV2.PO_NUMBER_FORMAT,
TO_CHAR(VP.PAYMENT_DATE,'YYYY') P_YEAR,
TO_CHAR(VP.PAYMENT_DATE,'Q') P_QTR
Tamir
Maybe you are looking for
-
Error on running Orace Bussiness Component Browser
Hello, I am running the sample application OnlineOrders of JDeveloper 3.2.3 against an Oracle 9i database, I tested OnlineOrdersModule and it did work, I can see most of the views on the Oracle Business Component Browser, but I get error with 2 of th
-
Can't receive calls after 3.0
Guys, After upgrading to 3.0, my iPhone started to playing up! first I cant receive calls normally however, I got full signal. Second, If I call someone and the he tried to call me back, at this case I can receive the call... strange!!! I'm with Optu
-
Hi, I found this message when I try to activate an Infopackage for loading an InfoCube with : "BEx could not be evaluated - No Error message". I don't found any data in my InfoCube: what can I do to have resolve my problem? Thks for your help.
-
File to Idoc - Generate one segment where sourcfields have identical values
Hello Team, This is a Flat File to Idoc scenario where one idoc is generated at the target. As i have mapped the Record(1..unbounded) with the E1MBXYI (1..9999), one record in the file would create one E1MBXYI- segment in the I
-
Hi. I have a File (Table) in Numbers . ( Without Formulas ) Is it possible to Export / Copy / Move it to a new Pages File ? The same with TextEdit to Pages .. Thanks.