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
Similar Messages
-
How to call a SP with dynamic columns and output results into a .csv file via SSIS
hi Folks, I have a challenging question here. I've created a SP called dbo.ResultsWithDynamicColumns and take one parameter of CONVERT(DATE,GETDATE()), the uniqueness of this SP is that the result does not have fixed columns as it's based on sales from previous
days. For example, Previous day, customers have purchased 20 products but today , 30 products have been purchased.
Right now, on SSMS, I am able to execute this SP when supplying a parameter. What I want to achieve here is to automate this process and send the result as a .csv file and SFTP to a server.
SFTP part is kinda easy as I can call WinSCP with proper script to handle it. How to export the result of a dynamic SP to a .CSV file?
I've tried
EXEC xp_cmdshell ' BCP " EXEC xxxx.[dbo].[ResultsWithDynamicColumns ] @dateFrom = ''2014-01-21''" queryout "c:\path\xxxx.dat" -T -c'
SSMS gives the following error as Error = [Microsoft][SQL Server Native Client 10.0]BCP host-files must contain at least one column
any ideas?
thanks
Hui
--Currently using Reporting Service 2000; Visual Studio .NET 2003; Visual Source Safe SSIS 2008 SSAS 2008, SVN --Hey Jakub, thanks and I did see the #temp table issue in our 2008R2. I finally figured it out in a different way... I manage to modify this dynamic SP to output results into
a physical table. This table will be dropped and recreated everytime when SP gets executed... After that, I used a SSIS pkg to output this table
to a file destination which is .csv.
The downside is that if this table structure ever gets changed, this SSIS pkg will fail or not fully reflecting the whole table. However, this won't happen often
and I can live with that at this moment.
Thanks
--Currently using Reporting Service 2000; Visual Studio .NET 2003; Visual Source Safe SSIS 2008 SSAS 2008, SVN -- -
How to create report with dynamic columns with static row labels
Hi All,
I am creating one report as per attached format. I have labels on the right side of the report
and data in 3 columns. The data is taken dynamically from the command query.
It gets data from 3 different result sets/command queries.
I tried creating the report horizontally instead of vertically, but the logo image I am not able to rotate in 270degrees.
Can anybody tell me how to create the report...??Hi Abhilash,
Thanks for the quick reply.
Actually the problem is with the image, as I am not able to rotate 270 degree. Crystal report cannot support the rotation of image.
i have another problem, I have to create a report in which
Lables are fixed on the left side of report and 3 columns per portrait page. Those columns are
dynamically created and shown in the report.
The format is like the above. Can you please help me in doing this report, as I tried it doing
with CrossTab. I am really stuck to this report. -
Advanced query with dynamic columns
Hi All,
I have a table with structure shown below. I need to pull data out of this table and the output should be in a format indicated by the select statement below. I have the following questions and I appreciate if someone could help.
1. I need to extract 3 years(current year + 2 historical years) worth of data out of this table dynamically(I can't hardcode year). How can I modify the code below so that the select statement returns 3 years worth of data dynamically?
2. Should I instead calculate each quarter in the select statement using "CASE"? Would this be a good idea and i wouldn't have to deal with the PIVOT function?
3. The reason I am asking about #2 is because our application requires the out field names to be as CYQ1, CYQ2, CYQ3, CYQ4, LYQ1, LYQ2, LYQ3, LYQ4 etc.(LY = last year). I am not sure if this is possible to do in Pivot table. Could the method outlines
in #2 be the best practice in my situation?
Thanks in advance for your thoughts.
DECLARE @Trans_Summary TABLE(
[Account_ID] [int] NULL,
[End_Date] DATE NULL,
[Amount] [float] NULL,
[Customer_ID] [int] NULL)
INSERT @Trans_Summary VALUES(1, '03/31/2013', 100, 123)
INSERT @Trans_Summary VALUES( 1, '01/31/2013', 200, 123)
INSERT @Trans_Summary VALUES( 1, '06/30/2013', 100, 123)
INSERT @Trans_Summary VALUES( 1, '09/30/2013', 100, 123)
INSERT @Trans_Summary VALUES( 1, '12/31/2013', 100, 123)
SELECT *
FROM @Trans_Summary
PIVOT(SUM([Amount])FOR End_Date IN ([2013-01-31], [2013-03-31], [2013-06-30], [2013-09-30], [2013-12-31])) AS TTYes, you should always use CASE for pivots and never use the PIVOT keyword. The latter gives you somewhat shorter query text, for very little gain.
As I understand what you are asking for, you can easily do it with CASE without dynamic SQL:
DECLARE @year char(4) = '2013',
@q1 = char(4) = '0331',
@q2 = char(4) = '0630',
@q3 = char(4) = '0930',
@q4 = char(4) = '1231'
SELECT Account_ID,
SUM(CASE WHEN End_Date = @year + @q1 THEN Amount END) AS CYQ1,
SUM(CASE WHEN End_Date = dateadd(YEAR, -1, @year + @q1) THEN Amount END) AS LYQ1,
FROM tbl
GROUP BY Account_ID
Well, maybe that can be done with PIVOT as well, but I have never learnt how to use the keyword. It just looks difficult to me. And useless.
Erland Sommarskog, SQL Server MVP, [email protected] -
hi
Using JDeveloper 10.1.3.3.0, I have this "Selected in Query" attribute, "Never" updatable, in my Entity Object.
The Entity Object is based on the SCOTT.EMP table and the attribute, called "BonusInfo", is defined using the expression " '[bonus info ' || (SAL * 2) || ']' ".
see http://verveja.footsteps.be/~verveja/files/oracle/NoColumnTypeFoundApp-v0.01.zip
While creating this Entity Object, I got a "Business Components" dialog that says:
"Column type is not specified for this attribute. Specifying column-type and precision results in better query performance at runtime. Do you wish to set column type to VARCHAR2(255)?"
I clicked "Yes".
I also created two View Objects based on this Entity Object.
In the "Create View Object" wizard "Step 4 of 7: Attribute Settings" I got a "Business Components" diaglog that says:
"Attributes selected in query with no column type found! Specifying column-type and precision results in better query performance at runtime. Do you wish to set default column type for these attributes?"
I clicked "Yes".
Testing the query in "Step 5 of 7: SQL Statement" showed "Query is valid.".
question:
Why do I keep getting the message ...
"Attributes selected in query with no column type found! Specifying column-type and precision results in better query performance at runtime. Do you wish to set default column type for these attributes?"
... in the View Object Editor if I click on different attributes?
(I don't get such a message the first time I click on an attribute after opening the View Object Editor, but after that it keeps popping up each time I click on a different attribute, no matter what I answer "Yes", "No" or "Cancel".)
many thanks
Jan VerveckenJan,
BC needs the column type and precision so that we can allocate the correct JDBC buffer size; otherwise we would just allocate 2k per string.
Blaise -
Difficult to achive the report layout with dynamic column names
I have a report layout as below.
So here the column names are dynamic.And each fixed row group has different calculations. I have a date parameter. If I select July 2013, then I need to show data from July 2012 to July 2013 with Columns(Jul-12, Aug-12...Jul-13). How to achive below layout
with dynamic columns?Hi Sarayu_CM,
According to your description, you want to filter the records of prior year based on only one parameter selection. Right?
In this scenario, we can create two parameters. The first one is for user to select. The second parameter is based on the first parameter selection. We don't need to specify Available Values for the second parameter, but we should use expression to specify
Default Values based on the first parameter selection. Use the expression below:
=DateAdd("m",-12,FormatDateTime(Parameters!param1.Value))
Then we just need to apply a filter on the matrix/dataset to get the records which the date is between values in these two parameters.
If you have any question, please feel free to ask.
Best Regards,
Simon Hou -
How to create table with dynamic rows
Hi Ppl,
I have an array lets say with length of n. I want to creata table with 2 columns and no of rows = array length.
lets say array length is 3 ( array[0] = 1, array[1] = 2, array[2] = 3) so the table should have 2 columns and 3 rows.
After creation of table I want to display each array value in each row.
Can somebody help me in this asap.
Thanks \
AshishHi, Thanks for reply... actually this is one part of rtf. I have put values from xml to an array and now I want to create a table with no of rows = length of array. so here xml will not be useful. could you pls think of it without xml.
result is like
lets says below is the array
array[0] = a
array[1] = b
array[2] = c
array length = 3
so there should be a table of 2 coulmns and 3 rows. Second column of first row will show 'a', Second column of second row wil show 'b' and Second column of third row will show 'c'.
Hope this is useful.
Thakns
Ashish -
Importing From Flat File with Dynamic Columns
HI
I am using ssis 2008,i have folder in which I have Four(4) “.txt” files each file will have 2 columns(ID, NAME). I loaded 4
files in one destination, but today I receive one more “.txt” file here we have 3 columns (ID, NAME, JOB) how can I get a message new column will receive in source. And how can I create in extra column in my destination table dynamically …please help meHi Sasidhar,
You need a Script Task to read the names and number of columns in the first row of the flat file each time and store it in a variable, then create a staging table dynamically based on this variable and modify the destination table definition if one ore more
new columns need to be added, and then use the staging table to load the destination table. I am afraid there is no available working script for your scenario, and you need some .NET coding experience to achieve your goal. Here is an example you can refer
to:
http://www.citagus.com/citagus/blog/importing-from-flat-file-with-dynamic-columns/
Regards,
Mike Yin
TechNet Community Support -
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. -
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 -
Attributes selected in query with no column type found! (solved)
Dear JHeadstart Team,
In the view object Editor I have two entity based attributes attrib1 and attrib2
both with type Number. Both have aliases with type number(9,0)
If attrib1 is null I want to have the value of attrib2.
In the expression box I put: nvl(attrib1,attrib2)
When I press the ok button I get the next error message.
"Attributes selected in query with no column type found!
Specifying column-type and precision results in better query performance at runtime.
Do you wish to set default column type for these attributes? "
When I say ok I get the next message:
"An error occurred. Unable to apply all the wizard changes.
Column type cannot be changed for Entity based attribute.
Exception: oracle.jbo.dt.objects.JboExeption."
The details button serves no extra information.
Since both the attributes have the same type I thought the nvl commando should work.
But what does the "no column type found" sentence mean?
regards,
Marcel.
Message was edited by:
user571204Thanks Jan,
You've put me on the right track.
I found out that this is only possible in the entity object class.
So I have to check my limited java skills. -
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 -
CREATE INDEX WITH DUPLICATE COLUMN NAME
Hi,
i need to interface our application with an Orale Bridge to CREATE INDEX with duplcate column Name.
For Example
CREATE index NLOT_FOURNLOT_idx ON NLOT(FOURNISSEUR ,NOLOT ,FOURNISSEUR ,NOBLFOUNISSEUR,NOLIGNEBL ,NOLOT ,QTECOLISRECUES ,CODENONQUALITE ,QTECOLISACCEPTE);
CREATE table NLOT(
FOURNISSEUR VARCHAR2(09)
,NOBLFOURNISSEUR VARCHAR2(13)
,NOLIGNEBL VARCHAR2(03)
,NOLOT VARCHAR2(20)
,QTECOLISRECUES VARCHAR2(10)
,CODENONQUALITE VARCHAR2(02)
,QTECOLISACCEPTE VARCHAR2(10)
,NOMBREDECOLISRE VARCHAR2(10)
,NOMBREDECOLISAC VARCHAR2(10)
,FILLER VARCHAR2(1)
,FILLE1 VARCHAR2(1)
,TYPEREFERENCE VARCHAR2(01)
,REFERENC1 VARCHAR2(15)
,CONTROLERECEPTI VARCHAR2(01)
,DATEDEPEREMPTIO VARCHAR2(8)
,CONTROLEPROCHAI VARCHAR2(1)
Thanks
PhilippeWell, you can't do it. ORA-957 is one of those irrevocable errors for which the solution is to remove the duplicate name from the SQL statement.
But, anyway, why do you want to do this? I would guess there's no performance benefit from having the same column indexed twice (of course it's impossible to test this, so it's just my opinion).
Cheers, APC -
DataTable with dynamic columns
Does somebody have an example of how to code a h:dataTable with dynamic columns? I have seen hints about how to do it in these two articles:
http://forum.java.sun.com/thread.jspa?forumID=427&threadID=5218508
http://forum.java.sun.com/thread.jspa?threadID=577589&messageID=2909047
but a complete working example would be really helpful.
I think the key is understanding the "binding" parameter to h:dataTable but I'm having a hard time understanding it. Thanks.I found it here:
http://balusc.blogspot.com/2006/06/using-datatables.html#PopulateDatatable -
Logic to upload file with dynamic columns
hi
in my requirement i hav given to add logic to upload file with dynamic columns so that this upload program can be reused.
this way the program is flexible, irrespective of the number of columns in the file.
can any one explain this?
and let me know what actually i hav to do.Check the program and the dynamic column is in the col_pos internal table and in the routines get_structure onwards.
https://www.sdn.sap.com/irj/sdn/wiki?path=/display/scm/dynamic%2bstructures%2band%2bcomponents
cheers
Aveek
Maybe you are looking for
-
The problem with the help page is that it starts after the browser is downloaded which is great, but I generally have very few questions about the browser once it is downloaded, it is getting it downloaded that generally provides the most difficulty.
-
Cannot re-download itunes error 7 windows error 126)
cannot re-download itunes error 7 windows error 126)
-
How come I have had two people send me picture texts and I have not received them? I have signed up and am paying for the multimedia services. Anyone else having this problem?
-
I have upgraded Flash to 10. and rebooted uninstalled fox, reinstalled and still get the same old thing. getting a little upset ''[Personal information removed by moderator. Please read [[Forum and chat rules and guidelines]], thanks.]''
-
Importing problem - Squares after track titles.
Whenever I try importing my (rather extensive) music folder into iTunes, I get squares after all the track titles. It imports those onto my iPod as well. It's hard to explain, so here is a picture http://usera.imagecave.com/auroraborealis/itu.PNG Can