SSIS Dynamic Columns in SQL

Hi All
I have an unusual issue and wondered if someone could assist. have a table which contains a list of columns which i need to feed into the query. I have written some dynamic SQL as shown:
Declare @KeyString varchar(100)
Declare @SQL1 nvarchar(max)
Set @KeyString=(Select STUFF((SELECT '+' + Attr FROM ave_control.ETL.Source inner JOIN [DM_AVE2].[Reference].[CRKAttr] on client = sourcename COLLATE DATABASE_DEFAULT where Client = 'Brampton' Order by AttrOrder FOR XML PATH('')),1,1,'') AS KeyString)
Set @SQL1 ='WITH CLAIMDATA AS(
Select
DB_NAME() AS DBName,
Convert(Varchar,UK.KMPONO) + ''/'' + Convert(Varchar,UK.KMPOSQ) + ''/'' + Convert(Varchar,UK.KMUGYR) + ''/'' + Convert(Varchar,UK.KMDANO) AS [POLICYREF],
Convert(Varchar,UK.KMPONO) + ''/'' + Convert(Varchar,UK.KMPOSQ) + ''/'' + Convert(Varchar,UK.KMUGYR) + ''/'' + Convert(Varchar,UK.KMDANO) + ''/'' + CONVERT(VarChar,UK.KMCMSQ) AS [CLAIMREF],
left(19000000+KMLODT,4) as [LOSSYEAR],
UK.KMLOCD AS [LOSSCODE],
CASE WHEN KMLOCD = '''' then COALESCE(UC.LOLODS,'''') ELSE UC.LOLODS END AS LOSSDESCRIPTION,
UK.KMEVCD AS [EVENTCODE],
KMCMDS AS [CLAIMDESCRIPTION],
CASE WHEN LEFT(KMCMDS,1) = ''@'' THEN ''Y'' ELSE ''N'' END AS [STATICRESERVEREVIEW],
CASE WHEN UCE.EVEVDS IS NULL then COALESCE(UCE.EVEVDS,'''') ELSE UCE.EVEVDS END AS [EVENTCODEDESCRIPTION]
FROM UKKMREP UK
LEFT JOIN UCLOREP UC ON UK.KMLOCD = UC.LOLOCD
LEFT JOIN UCEVREP UCE ON UK.KMEVCD = UCE.EVEVCD),
COGDATA AS(
SELECT TOP 100 PERCENT
CONVERT(Varchar,POLICY)+''/''+CONVERT(Varchar,CO.SEQ)+''/''+CONVERT(Varchar,CO.[YEAR])+''/''+CONVERT(Varchar,CO.[DEC])+''/''+CONVERT(Varchar,CO.CLAIM) AS [CLAIMREF],
[Type],
SUM(isnull(CO.KCR,0)+isnull(CO.ACR,0)+isnull(CO.[OCR],0)+isnull(CO.[EXP],0)+isnull(Co.[LOC],0)) AS OLR
FROM COG626A CO
Group by CONVERT(Varchar,POLICY)+''/''+CONVERT(Varchar,CO.SEQ)+''/''+CONVERT(Varchar,CO.[YEAR])+''/''+CONVERT(Varchar,CO.[DEC])+''/''+CONVERT(Varchar,CO.CLAIM), [Type]
ORDER BY CLAIMREF
CLAIMRCData AS(
Select distinct
DB_NAME() As DBNAME,
Convert(Varchar,UK.KMPONO) + ''/'' + Convert(Varchar,UK.KMPOSQ) + ''/'' + Convert(Varchar,UK.KMUGYR) + ''/'' + Convert(Varchar,UK.KMDANO) + ''/'' + CONVERT(VarChar,UK.KMCMSQ) AS [CLAIMREF],
Convert(varchar,isnull(pocscd,'''')) as POCSCD,
Convert(varchar,isnull(pomkrf,'''')) AS PMKRF,
Convert(varchar,isnull(poplcd,'''')) AS POPLCD,
Convert(varchar,isnull(poqdfg,'''')) AS POQDFG,
Convert(varchar,isnull(pougty,'''')) AS POUGTY,
Convert(varchar,isnull(pogucd,'''')) AS POGUCD,
Convert(varchar,isnull(kmbhcd,'''')) AS KMBHCD,
Convert(varchar,isnull(kmcccd,'''')) AS KMCCCD,
Convert(varchar,isnull(kmdpdv,'''')) AS KMDPDV,
Convert(varchar,isnull(kmevcd,'''')) AS KMEVCD,
Convert(varchar,isnull(kmimcd,'''')) AS KMIMCD,
Convert(varchar,isnull(kmiycd,'''')) AS KMIYCD,
Convert(varchar,isnull(kmlocd,'''')) AS KMLOCD
from UPPOREP UP Left join UKKMREP UK on UP.POPONO = UK.KMPONO AND UP.POPOSQ = KMPOSQ AND UP.POUGYR = UK.kmugyr AND UP.PODANO = UK.KMDANO)
Select distinct
C1.DBName,
C1.POLICYREF,
C1.CLAIMREF,
C1.LossDescription,
C1.LOSSCODE,
C1.LOSSYEAR,
C1.EventCode,
C1.ClaimDescription,
C1.StaticReserveReview,
C1.EventCodeDescription,'
+ @KeyString + ' AS ClaimKey,
Round(CG1.OLR,2) as [OLR],
CASE WHEN CG1.OLR <> 0 THEN ''OPEN'' ELSE ''CLOSED'' END AS [ClaimStatus]
FROM CLAIMDATA C1
LEFT JOIN COGDATA CG1 on C1.CLAIMREF = CG1.CLAIMREF
LEFT JOIN CLAIMRCData CR on C1.CLAIMREF = CR.CLAIMREF
UNION
Select distinct
C1.DBName,
C1.POLICYREF,
SUBSTRING(CG1.ClaimRef,1,Len(CG1.ClaimRef)-2) + ''/0'',
'''' AS LossDescription,
'''' AS LossCode,
1912 AS LossYear,
'''' AS EventCode,
'''' AS ClaimDescription,
'''' AS StaticReserveReview,
'''' AS EventCodeDescription,'
+ @KeyString + ' AS ClaimKey,
0 AS OLR,
''CLOSED'' AS CLAIMSTATUS
From CLAIMDATA C1
INNER JOIN COGDATA CG1 on C1.CLAIMREF = CG1.CLAIMREF
LEFT JOIN CLAIMRCData CR on C1.CLAIMREF = CR.CLAIMREF
Order by C1.POLICYREF'
Select @SQL1
I always want to output @Keystring using a DFT but depending on the client the Keystring is set to a different group of columns and selects a different set of columns from the CLAIMRCData loop.
I tried inserting it as dynamic SQL as a variable but cannot get it to parse - does anyone know how to achieve this?
Here is the output from the Select @SQL1 which always returns the value I want and if i execute this and change the clientname it successfully returns the right claimkey each time - i.e. another client has 3 columns and these are successfully parsed
- i just dont know how to get it into SSIS. Output as shown:
WITH CLAIMDATA AS(
Select
DB_NAME() AS DBName,
Convert(Varchar,UK.KMPONO) + '/' + Convert(Varchar,UK.KMPOSQ) + '/' + Convert(Varchar,UK.KMUGYR) + '/' + Convert(Varchar,UK.KMDANO) AS [POLICYREF],
Convert(Varchar,UK.KMPONO) + '/' + Convert(Varchar,UK.KMPOSQ) + '/' + Convert(Varchar,UK.KMUGYR) + '/' + Convert(Varchar,UK.KMDANO) + '/' + CONVERT(VarChar,UK.KMCMSQ) AS [CLAIMREF],
left(19000000+KMLODT,4) as [LOSSYEAR],
UK.KMLOCD AS [LOSSCODE],
CASE WHEN KMLOCD = '' then COALESCE(UC.LOLODS,'') ELSE UC.LOLODS END AS LOSSDESCRIPTION,
UK.KMEVCD AS [EVENTCODE],
KMCMDS AS [CLAIMDESCRIPTION],
CASE WHEN LEFT(KMCMDS,1) = '@' THEN 'Y' ELSE 'N' END AS [STATICRESERVEREVIEW],
CASE WHEN UCE.EVEVDS IS NULL then COALESCE(UCE.EVEVDS,'') ELSE UCE.EVEVDS END AS [EVENTCODEDESCRIPTION]
FROM UKKMREP UK
LEFT JOIN UCLOREP UC ON UK.KMLOCD = UC.LOLOCD
LEFT JOIN UCEVREP UCE ON UK.KMEVCD = UCE.EVEVCD),
COGDATA AS(
SELECT TOP 100 PERCENT
CONVERT(Varchar,POLICY)+'/'+CONVERT(Varchar,CO.SEQ)+'/'+CONVERT(Varchar,CO.[YEAR])+'/'+CONVERT(Varchar,CO.[DEC])+'/'+CONVERT(Varchar,CO.CLAIM) AS [CLAIMREF],
[Type],
SUM(isnull(CO.KCR,0)+isnull(CO.ACR,0)+isnull(CO.[OCR],0)+isnull(CO.[EXP],0)+isnull(Co.[LOC],0)) AS OLR
FROM COG626A CO
Group by CONVERT(Varchar,POLICY)+'/'+CONVERT(Varchar,CO.SEQ)+'/'+CONVERT(Varchar,CO.[YEAR])+'/'+CONVERT(Varchar,CO.[DEC])+'/'+CONVERT(Varchar,CO.CLAIM), [Type]
ORDER BY CLAIMREF
CLAIMRCData AS(
Select distinct
DB_NAME() As DBNAME,
Convert(Varchar,UK.KMPONO) + '/' + Convert(Varchar,UK.KMPOSQ) + '/' + Convert(Varchar,UK.KMUGYR) + '/' + Convert(Varchar,UK.KMDANO) + '/' + CONVERT(VarChar,UK.KMCMSQ) AS [CLAIMREF],
Convert(varchar,isnull(pocscd,'')) as POCSCD,
Convert(varchar,isnull(pomkrf,'')) AS PMKRF,
Convert(varchar,isnull(poplcd,'')) AS POPLCD,
Convert(varchar,isnull(poqdfg,'')) AS POQDFG,
Convert(varchar,isnull(pougty,'')) AS POUGTY,
Convert(varchar,isnull(pogucd,'')) AS POGUCD,
Convert(varchar,isnull(kmbhcd,'')) AS KMBHCD,
Convert(varchar,isnull(kmcccd,'')) AS KMCCCD,
Convert(varchar,isnull(kmdpdv,'')) AS KMDPDV,
Convert(varchar,isnull(kmevcd,'')) AS KMEVCD,
Convert(varchar,isnull(kmimcd,'')) AS KMIMCD,
Convert(varchar,isnull(kmiycd,'')) AS KMIYCD,
Convert(varchar,isnull(kmlocd,'')) AS KMLOCD
from UPPOREP UP Left join UKKMREP UK on UP.POPONO = UK.KMPONO AND UP.POPOSQ = KMPOSQ AND UP.POUGYR = UK.kmugyr AND UP.PODANO = UK.KMDANO)
Select distinct
C1.DBName,
C1.POLICYREF,
C1.CLAIMREF,
C1.LossDescription,
C1.LOSSCODE,
C1.LOSSYEAR,
C1.EventCode,
C1.ClaimDescription,
C1.StaticReserveReview,
C1.EventCodeDescription,pogucd+pougty AS ClaimKey,
Round(CG1.OLR,2) as [OLR],
CASE WHEN CG1.OLR <> 0 THEN 'OPEN' ELSE 'CLOSED' END AS [ClaimStatus]
FROM CLAIMDATA C1
LEFT JOIN COGDATA CG1 on C1.CLAIMREF = CG1.CLAIMREF
LEFT JOIN CLAIMRCData CR on C1.CLAIMREF = CR.CLAIMREF
UNION
Select distinct
C1.DBName,
C1.POLICYREF,
SUBSTRING(CG1.ClaimRef,1,Len(CG1.ClaimRef)-2) + '/0',
'' AS LossDescription,
'' AS LossCode,
1912 AS LossYear,
'' AS EventCode,
'' AS ClaimDescription,
'' AS StaticReserveReview,
'' AS EventCodeDescription,pogucd+pougty AS ClaimKey,
0 AS OLR,
'CLOSED' AS CLAIMSTATUS
From CLAIMDATA C1
INNER JOIN COGDATA CG1 on C1.CLAIMREF = CG1.CLAIMREF
LEFT JOIN CLAIMRCData CR on C1.CLAIMREF = CR.CLAIMREF
Order by C1.POLICYREF
any help would be greatly appreciated - oh version is SQL 2014 SSIS
Thanks
James

When you say not able to parse, can you give the expression itself?
And in what SSIS component do you run this query?
And what error do you get?
My cursory look (too much code to digest frankly) says you need to wrap it into a stored procedure.
Arthur
MyBlog
Twitter

Similar Messages

  • Dynamic column name sql?

    I need to do a select statement using dynamic column names. Can it be done WITHOUT building a string to execute the sql?
    In other words, I want to use a variable name in the SELECT part of a statement.
    Thanks

    Properly done, there shouldn't be a great difference in the performance of static and dynamic SQL. Of course, dynamic SQL is a whole lot more complicated to get right. It's also rather at odds with your requirement that column names get passed in dynamically-- if you don't know what columns you're going to select at compile time, you can't use static SQL.
    That said, there are a handful of tricks around using Oracle's built-in XML processing functionality to simulate dynamic SQL. This is almost certainly less efficient than doing dynamic SQL in your case, and a whole lot more complicated, but it's technically not dynamic SQL.
    The proper response, though, is almost certainly to either
    1) figure out how to design the application so that column names need not be passed in at runtime or
    2) use dynamic SQL.
    If at all possible, option 1 is generally preferable. While there are situations where dynamic SQL is necessary, those tend to be rather rare.
    Justin

  • How to Generate Dynamic Columns from SQL

    Hi Friends,
    I want to create a data fromat like This
    Showroom / date    01-01-09        02-01-09     03-01-09     04-01-09      05-01-09     06-01-09     07-01-09   
    S1                           20                      10              09            90             90                  10            100
    S2                           10                       1                1              2               6                    2             10
    S3                            5                        7                 9             1               2                    3             12This Data is Just like Matriz Reports....................................
    Here i Want to Generate Date column value Dynamically.....................is it possible through SQL
    the values are Sales value for each showroom for diffrent date value
    all sale,showroom and Date Column are in one Table......................
    It should Generate date Dynamically depending on User VAlues./..............
    Thanks in Advance

    something to play with (not tested as I don't have database access)
    declare
    /* assuming table showroom_sales has columns a_showroom,a_date,a_sale */
      the_sql varchar2(32000) := 'select a_showroom';
      day_from date := to_date('20090101','yyyymmdd');
      day_till date := to_date('20090107','yyyymmdd');
    begin
      for d in (select a_date from showroom_sales where a_date between day_from and day_till)
      loop
        the_sql := the_sql ||
                   ',max(decode(a_date,to_date('''||to_char(d.a_date,'yyyymmdd')||''',''yyyymmdd''),a_sale,null)) "'||to_char(d.a_date,'dd-mm-rr')||'"'
      end loop;
      the_sql := the_sql || ' from showroom_sales group by a_showroom order by a_showroom ';
      dbms_output.put_line(the_sql);  /* to verify if query is correct or not */
    end;the code above should generate something like (provided all those dates appear in your showroom_sales table)
    select a_showroom,
           max(decode(a_date,to_date('20090101','yyyymmdd'),a_sale,null)) "01-01-09",
           max(decode(a_date,to_date('20090102','yyyymmdd'),a_sale,null)) "02-01-09",
           max(decode(a_date,to_date('20090103','yyyymmdd'),a_sale,null)) "03-01-09",
           max(decode(a_date,to_date('20090104','yyyymmdd'),a_sale,null)) "04-01-09",
           max(decode(a_date,to_date('20090105','yyyymmdd'),a_sale,null)) "05-01-09",
           max(decode(a_date,to_date('20090106','yyyymmdd'),a_sale,null)) "06-01-09",
           max(decode(a_date,to_date('20090107','yyyymmdd'),a_sale,null)) "07-01-09"
      from showroom_sales
    group by a_showroom
    order by a_showroom to be executed to get the result as required
    Regards
    Etbin

  • Dynamic Column in SQL-Statement

    Hello,
    can i do something like this?
    SELECT :P101_Lang FROM LANGUAGE where NAME = 'P5_REPORT'
    Many thanks in advance

    I have a similar situation, but rather than a select statement, it's an update statement. I'm still VERY new to APEX and Oracle SQL. I'm used to using MS Access & VBA, but the project that was handed to me is APEX, so I'm doing my best to learn it.
    Page Items:
    P4_COLUMN_NAMES (Listbox)
    P4_TEXT ENTRY (text field)
    P4_ITEM_ENTRY (List management)
    The process that should happen is this: User picks several items from ITEM_ENTRY, then chooses which column to update in COLUMN_NAMES to whatever is in TEXT_ENTRY.
    Using the APEX function to cycle through the ITEM_ENTRY results, I've tried SEVERAL ways, all of which resulted in multiple errors. I've spent over a week, off and on, on this issue. Here is the most basic version.
    declarev_p1_x_arr apex_application_global.vc_arr2;
    begin
    v_p1_x_arr := apex_util.string_to_table(:P4_ITEM_ENTRY);
    for i in 1..v_p1_x_arr.count loop
    UPDATE SMT SET :P4_COLUMN_NAMES = :P4_TEXT_ENTRY
    end loop;
    end;>
    I've tried this as an app process and a page process. Until I found this thread, I didn't even know there was a PL/SQL region. ((told ya I'm a newbie)) It seems like the solution you provided to the other person is pretty close to what I'm looking for. However, I don't know how to implement it with the APEX function above.
    Any help would be GREATLY appreciated!
    Thanks,
    -- Matt

  • Converting Oracle TIMESTAMP(4) column to SQL datetime column conversion error in ssis

    I could not able to convert Oracle TIMESTAMP(4) column to SQL datetime column conversion error in ssis.
    I'm connecting OLEDD Oracle Source to OLEDB SQL Destination in SSIS package. I'm trying to insert data from oracle datetime column into sql datetime column. I'm getting some errors.
    Please provide helpful info.

    You can transform the data types directly at the source by writing a proper SQL statement, or you can convert them using the data conversion component.
    Please refer the below link
    http://stackoverflow.com/questions/6256168/how-to-convert-a-timestamp-in-string-format-to-datetime-data-type-within-a-packa

  • How to change recordset bahaviour to accept dynamic column names in the where clause

    Hi
    im using php-mysql and i make a recordset and i want to make the column names in the where clause to be dynamic like
    "select id,name from mytable where $tablename-$myvar";
    but when i do this my i break the recordset and it disappear
    and when i use variables from advanced recordset it only dynamic for the value of the column not for the column name
    and when i write the column name to dynamic as above by hand it truns a red exclamation mark on the server behaviour panel
    so i think the only way is to change the recordset behaviour is it? if so How to make it accept dynamic column names?
    thanks in advance.

    As bregent has already explained to you, customizing the recordset code will result in Dreamweaver no longer recognizing the server behavior. This isn't a problem, but it does mean that you need to lay out your dynamic text with the Bindings panel before making any changes. Once you have changed the recordset code, the Bindings panel will no longer recognize the recordset fields.
    Using a variable to choose a column name is quite simple, but you need to take some security measures to ensure that the value passed through the query string isn't attempting SQL injection. An effective way of doing this is to create an array of acceptable column names, and check that the value matches.
    // create array of acceptable values
    $valid = array('column_name1', 'column_name2', 'column_name3');
    // if the query string contains an acceptable column name, use it
    if (isset($_GET['colname']) && in_array($_GET['colname'], $valid)) {
      $col = $GET['colname'];
    } else {
      // set a default value if the submitted one was invalid
      $col = 'column_name1'
    You can then use $col directly in the SQL query.

  • Interactive Report - Icon View - Dynamic Columns per Rows ?

    Hi all,
    We use the icon view functionnality in Interactive Report.
    Is there a way to display the 'columns per row' attribute as an application item and set it dynamical via PL/SQL ?
    Any suggestions?
    Thanks in advance for advices,
    Regards,
    Grégory

    Hi,
    Apex 4.0 interactive reports and images (Scott's thread)
    Have some useful information and pointers to the solution you are looking for.
    I hope this help.
    Thank you,
    Ranish

  • How many columns a sql selects

    I need to find out how many columns are in a sql statement like below:
    sql = "select id, decode(description,'','No decription', description), comment from my_table";
    The sql string is build dynamically so I don't know it when I write the code. I need to know before I do
    call rs.next(), because I need to set up the table header so I need to know how many columns the sql is selecting.
    Thanks inadvance.
    Botao

    You can use the interface ResultSetMetaData,below are some methods of it.
    int getColumnCount()
    Returns the number of columns in this ResultSet object.
    String getColumnName(int column)
    Get the designated column's name.
    int getColumnType(int column)
    Retrieves the designated column's SQL type.
    for more infomation ,you can refer to JDBC Online Document.

  • Saving result from sp_executesql into a variable and using dynamic column name - getting error "Error converting data type varchar to numeric"

    Im getting an error when running a procedure that includes this code.
    I need to select from a dynamic column name and save the result in a variable, but seem to be having trouble with the values being fed to sp_executesql
    DECLARE @retval AS DECIMAL(12,2)
    DECLARE @MonthVal VARCHAR(20), @SpreadKeyVal INT
    DECLARE @sqlcmd AS NVARCHAR(150)
    DECLARE @paramdef NVARCHAR(150)
    SET @MonthVal = 'Month' + CAST(@MonthNumber AS VARCHAR(2) );
    SET @SpreadKeyVal = @SpreadKey; --CAST(@SpreadKey AS VARCHAR(10) );
    SET @sqlcmd = N' SELECT @retvalout = @MonthVal FROM dbo.CourseSpread WHERE CourseSpreadId = @SpreadKeyVal';
    SET @paramdef = N'@MonthVal VARCHAR(20), @SpreadKeyVal INT, @retvalout DECIMAL(12,2) OUTPUT'
    --default
    SET @retval = 0.0;
    EXECUTE sys.sp_executesql @sqlcmd,@paramdef, @MonthVal = 'Month4',@SpreadKeyVal = 1, @retvalout = @retval OUTPUT;
    SELECT @retval
    DECLARE @return_value DECIMAL(12,2)
    EXEC @return_value = [dbo].[GetSpreadValueByMonthNumber]
    @SpreadKey = 1,
    @MonthNumber = 4
    SELECT 'Return Value' = @return_value
    Msg 8114, Level 16, State 5, Line 1
    Error converting data type varchar to numeric.

    Please follow basic Netiquette and post the DDL we need to answer this. Follow industry and ANSI/ISO standards in your data. You should follow ISO-11179 rules for naming data elements. You should follow ISO-8601 rules for displaying temporal data. We need
    to know the data types, keys and constraints on the table. Avoid dialect in favor of ANSI/ISO Standard SQL. And you need to read and download the PDF for: 
    https://www.simple-talk.com/books/sql-books/119-sql-code-smells/
    >> I need to select from a dynamic column name and save the result in a variable, but seem to be having trouble with the values being fed to sp_executesql <<
    This is so very, very wrong! A column is an attribute of an entity. The idea that you are so screwed up that you have no idea if you want
    the shoe size, the phone number or something else at run time of this entity. 
    In Software Engineering we have a principle called cohesion that says a model should do one and only one task, have one and only one entry point, and one and only one exit point. 
    Hey, on a scale from 1 to 10, what color is your favorite letter of the alphabet? Yes, your mindset is that level of sillyity and absurdity. 
    Do you know that SQL is a declarative language? This family of languages does not use local variables! 
    Now think about “month_val” and what it means. A month is a temporal unit of measurement, so this is as silly as saying “liter_val” in your code. Why did you use “sp_” on a procedure? It has special meaning in T-SQL.  
    Think about how silly this is: 
     SET @month_val = 'Month' + CAST(@month_nbr AS VARCHAR(2));
    We do not do display formatting in a query. This is a violation of at the tiered architecture principle. We have a presentation layer. But more than that, the INTERVAL temporal data type is a {year-month} and never just a month. This is fundamental. 
    We need to see the DDL so we can re-write this mess. Want to fix it or not?
    --CELKO-- Books in Celko Series for Morgan-Kaufmann Publishing: Analytics and OLAP in SQL / Data and Databases: Concepts in Practice Data / Measurements and Standards in SQL SQL for Smarties / SQL Programming Style / SQL Puzzles and Answers / Thinking
    in Sets / Trees and Hierarchies in SQL

  • 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 me

    Hi 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

  • Dynamic column names

    I created a line chart with the following sql statement:
    select null link, periode_jaar, sum(totaal) total from V_KPL_VZ_OWB@rapportage_dwhtest
    where periode_jaar = (Select max(periode_jaar) from V_KPL_VZ_OWB@rapportage_dwhtest)
    group by periode_jaar
    order by periode_jaar
    In the legend of the chart the line is named total. I would like have it named for example: Total 2009
    So how i create the dynamic column? Any ideas? Tnx in advnaced

    tnx for helping, i posted my xml code below where to put the tag: <format>{%Name} ({%Value})</format>
    i assume i have to replace %Name with my sirie name and the %Value with the name i wanted?
    Is it possible to replace %Value with an item like :p1_year
    &#60;?xml version = "1.0" encoding="utf-8" standalone = "yes"?&#62;
    &#60;root&#62;
    &#60;type&#62;
    &#60;chart type="2DLine"&#62;
    &#60;animation enabled="yes" appearance="size" speed="10" /&#62;
    &#60;hints auto_size="yes"&#62;
    &#60;text&#62;&#60;![CDATA[{NAME}, {VALUE}]]&#62;&#60;/text&#62;
    &#60;font type="Verdana" size="10" color="0x000000" /&#62;
    &#60;/hints&#62;
    &#60;names show="yes" width="150" placement="chart" position="bottom" &#62;
    &#60;font type="Verdana" size="10" color="0x000000" /&#62;
    &#60;/names&#62;
    &#60;values show="no" prefix="" postfix="%" decimal_separator="," decimal_places="0" /&#62;
    &#60;arguments show="no" /&#62;
    &#60;line_chart left_space="5" right_space="5"&#62;
    &#60;block_names enabled="no" /&#62;
    &#60;/line_chart&#62;
    &#60;/chart&#62;
    &#60;workspace&#62;
    &#60;background enabled="yes" type="solid" color="0xffffff" alpha="0" /&#62;
    &#60;base_area enabled="no" /&#62;
    &#60;chart_area enabled="yes" x="80" y="50" width="380" height="280" deep="0"&#62;
    &#60;background enabled="no"/&#62;
    &#60;border enabled="yes" size="1"/&#62;
    &#60;/chart_area&#62;
    &#60;x_axis name="Jaar" smart="yes" position="center_bottom" &#62;
    &#60;font type="Verdana" size="14" color="0x000000" bold="no" align="center" /&#62;
    &#60;/x_axis&#62;
    &#60;y_axis name="%" smart="yes" position="left_center" &#62;
    &#60;font type="Verdana" size="14" color="0x000000" bold="no" align="center" /&#62;
    &#60;/y_axis&#62;
    &#60;grid&#62;
    &#60;values /&#62;
    &#60;/grid&#62;
    &#60;/workspace&#62;
    &#60;legend enabled="yes" x="480" y="50"&#62;
    &#60;font type="Verdana" size="10" color="0x000000" /&#62;
    &#60;/names&#62;
    &#60;values enabled="YES"/&#62;
    &#60;scroller enabled="no"/&#62;
    &#60;header enabled="no"/&#62;
    &#60;background alpha="0"/&#62;
    &#60;/legend&#62;
    &#60;/type&#62;
    #DATA#
    &#60;/root&#62;

  • Dynamic column selection

    I want to select specific columns from a table dynamically which are basically the columns returned by quering the user_tab_columns data dictionary which in turn has to satisfy certain condition for me.
    So, what I want to do is something like:
    SELECT b.(dynamic column list from a)
    FROM b,
    (SELECT column_name FROM user_tab_columns WHERE table_name='STH' AND ........) a
    any help will be greatly appreciated.

    sql>create or replace procedure p_dynamic_sql
      2  is
      3    v_sql varchar2(4000);
      4  begin
      5    v_sql := 'select ';
      6    for r in (select column_name
      7                from user_tab_cols
      8               where table_name = 'EMP'
      9                 and column_name like 'E%') loop
    10      v_sql := v_sql || r.column_name || ',';
    11    end loop;
    12    v_sql := rtrim(v_sql, ',') || ' from emp';
    13    dbms_output.put_line( v_sql );
    14    -- do something with SQL (open cursor, etc.)   
    15  end;
    16  /
    Procedure created.
    sql>exec p_dynamic_sql
    select EMPNO,ENAME from emp
    PL/SQL procedure successfully completed.

  • Set label of an item dynamically through pl/sql function

    Hi ,
    How Can I get the label of an item dynamically through a pl/sql function.
    I have a table that stores the label name for these items.
    I want to set the label for the item based on the value in my table ?
    Is it possible ?
    any ideas ?
    Thanks in advance,
    Dippy
    Edited by: Dippy on Feb 23, 2010 11:02 AM
    Edited by: Dippy on Feb 23, 2010 11:02 AM

    If I understand you correctly, you are using a standard report region, but want to dynamically name the column headers? The only way I've been able to get this to work is to create hidden items for each column header, calculate the value you want for each item, then reference the item in the column header using &item_X. for the column header name.
    The problem is that at this point, APEX doesn't allow for dynamic column naming unless you want to do everything yourself using a PL/SQL process that builds the report table manually. I've done that for certain complex reporting tools.
    I understand it's tedious to create all the column header items; I have one report that has over 72 items used in this way. It was a pain, but it got the job done.

  • Dynamic column heading in csv export not working

    Hi,
    I have a SQL report where the column headings are defined dynamically. for an example let's say I have a report
    SELECT NAME, TODAY'S_DATE FROM TABLE A.
    Under report attribute column I have defined column heading as "&P_todays_date.”. This item has source value “Select sysdate from dual. When I export the data into csv file the dynamic column headings are coming as blank.
    Any suggestions?
    Thanks,
    Manish

    You are posting this question in the PeopleSoft forums. I think it belongs in the BI section:
    https://forums.oracle.com/forums/category.jspa?categoryID=16

  • Dynamic column names in Oracle

    HI SOS!! calling for help...
    i am trying to query the following. I want to remove the duplicates in the ID, and combine them into one... While doing so, I want to keep the data as it is by creating dynamic columns reason_1, reason_2, reason_3 with their corresponding TIME. In case of same reasons, I want to add the TIME. The database is as follows:
    ID     REASON     TIME
    A     41A..........     27
    A     93K..........16
    B     89C...........3
    B     93K...........7
    B     48C..........     4
    C     93K..........     24
    C     93K..........     7
    C     48C.........10
    Expected Result is
    ID     REASON_1......TIME_1.... REASON_2...TIME_2....REASON_3.........TIME_3
    A........ 41A............ 27........... 93K............16          
    B........ 89C............ 3............ 93K............7...........48C.................. 4
    C........ 93K........... 31.......... 48C..............10          
    Would be grateful if someone could try helping me out of this as early as possible.
    Edited by: 968125 on Oct 28, 2012 11:01 PM

    You still haven't made it clear what the requirement is.
    Is there a maximum number of reasons that can occur per ID? If so, you can code the pivoting of your data with something like:
    SQL> ed
    Wrote file afiedt.buf
      1  with t as (select 'A' as ID, '41A' as reason, 27 as time from dual union all
      2             select 'A', '93K', 16 from dual union all
      3             select 'B', '89C', 3 from dual union all
      4             select 'B', '93K', 7 from dual union all
      5             select 'B', '48C', 4 from dual union all
      6             select 'C', '93K', 24 from dual union all
      7             select 'C', '93K', 7 from dual union all
      8             select 'C', '48C', 10 from dual)
      9  --
    10  -- END OF TEST DATA TABLE SIMULATED USING 'WITH' CLAUSE
    11  -- SIMPLY USE THE SELECT STATEMENT BELOW ON YOUR OWN TABLE
    12  --
    13  select id
    14        ,max(decode(rn,1,reason)) as reason_1
    15        ,max(decode(rn,1,time)) as time_1
    16        ,max(decode(rn,2,reason)) as reason_2
    17        ,max(decode(rn,2,time)) as time_2
    18        ,max(decode(rn,3,reason)) as reason_3
    19        ,max(decode(rn,3,time)) as time_3
    20        ,max(decode(rn,4,reason)) as reason_4
    21        ,max(decode(rn,4,time)) as time_4
    22        ,max(decode(rn,5,reason)) as reason_5
    23        ,max(decode(rn,5,time)) as time_5
    24  from (/* assign some row numbers within each ID, ordering by 'reason' then 'time' */
    25        select id, reason, time
    26              ,row_number() over (partition by id order by reason, time) as rn
    27        from   t
    28       )
    29* group by id
    SQL> /
    I REA     TIME_1 REA     TIME_2 REA     TIME_3 REA     TIME_4 REA     TIME_5
    A 41A         27 93K         16
    B 48C          4 89C          3 93K          7
    C 48C         10 93K          7 93K         24In this example, it will cater for up to 5 reasons/times per ID... and you can code for more if you need very easily.
    Also, as you're using 11g, you can use the new PIVOT query, for which you can find plenty of examples if you google or search these forums, or follow the FAQ link.
    If you don't have any idea how many reasons there could be, then you really are looking at generating columns dynamically.
    The problem with that is, because Oracle needs to know the SQL projection (see the FAQ link already provided), it has to know how many columns are going to be returned from a query before any data is fetched... but you are saying that the columns returned have to be based on the data itself. To do that you have two main options:
    1) You query the data once to determine how many columns you are going to need and then dynamically build up a query in PL/SQL code with the right number of columns (or use one of the other dynamic methods shown in the FAQ)
    or
    2) You step back and ask yourself if SQL is really the best place to be trying to produce this output. Reporting tools are often better suited to this requirement as they are made to query the data back from a database and then pivot and layout the data based on the data returned.

Maybe you are looking for

  • External Hard drive wont show up in Finder

    Hi, After Mountain Update, the external hard drive icon wont show up in Finder sidebar, Desktop and in Disk Utility. Is there anything which needs to be set in System Preference ?? I have the External Hard Disk checkbox checked in Finder Preference,

  • EJB Transaction does not work

    Hi, I have a servlet, a session bean, and an entity bean. A servlet doesn't have any transaction attribute, a session bean has Required, and an entity bean has Required. I have the code like the following: Servlet: EJBDelegate ed = new EJBDelegate();

  • Stop sending signal to external display without unplugging the cable

    Stupid question: if I toggle through the display settings (F7), it doesn't seem as if any go to shutting off the external display (like maybe I want to make a change I don't want my audience to see, I would like to shut it off without unplugging, the

  • Form Printing :In VIB4 control the Tree .

    Dear All, When printing billing document in VIB4,there will be tree formed in the left side of the Screen. Can we control the tree contents based on the Sales Organisation in the Customisation settings. Regards, Seshadri G

  • Export SharePoint List data to SQL Server 2005 Database

    Hello Everybody, I am presently working on a project which handles much larger amount of data. The architecture of the application demands extracting records from the SharePoint (WSS 3.0) and insert into a SQL Server 2005 database. I need to run this