Column values to be converted as Column names

I have a table called Name 
CREATE TABLE Name(
[Name] [varchar](10) NULL
INSERT INTO Name VALUES ('XXX')
INSERT INTO Name VALUES ('PPP')
INSERT INTO Name VALUES ('MNO')
INSERT INTO Name VALUES ('PQR')
i have a requirement where the values of column(Name)to be converted as  Column name  as shown below.
can anybody please  help me .

Hope below queries help you:
-- Option 1
SELECT
MAX(CASE WHEN Name = 'XXX' THEN Name END) AS 'XXX' ,
MAX(CASE WHEN Name = 'PPP' THEN Name END) AS 'PPP' ,
MAX(CASE WHEN Name = 'MNO' THEN Name END) AS 'MNO' ,
MAX(CASE WHEN Name = 'PQR' THEN Name END) AS 'PQR'
FROM Name
-- Option 2
DECLARE @cols AS NVARCHAR(MAX),
@query AS NVARCHAR(MAX)
select @cols = STUFF((SELECT ',' + QUOTENAME(Name)
from Name
group by Name
FOR XML PATH(''), TYPE
).value('.', 'NVARCHAR(MAX)')
,1,1,'')
set @query = 'SELECT ' + @cols + ' from
select Name
from Name
) x
pivot
max(Name)
for Name in (' + @cols + ')
) p '
execute(@query)
-Vaibhav Chaudhari

Similar Messages

  • Using Column Value in CSS Style for Column in Report

    I am trying to apply a CSS style (background color) to a column in a report based on another column.
    So for the Column attributes for a specific column, I would like to be able to add this to the 'CSS Style' Field under the group, "Column Formatting":
    background-color:#BKG_COLOR#;
    It doesn't seem to be taking my column value, which is #daf2ea
    In the CSS Style Field, if I change it to: background-color:#daf2ea - then it works.
    So it doesn't seem to take my column value of #BKG_COLOR" in the CSS Style field.
    Any ideas? Do I need to use the 'HTML Expression' field instead, and how would I do that?
    Thanks,
    John

    Hi,
    that's correct, custom report templates will do.
    I find them sometimes quite limited, though. And I always ask myself "how would I do it without APEX", because there's often a lean jQuery solution that affords less coding.
    If you employ a so called "marker class" that depends on your colour value, you could begin like in the previous answer and enter the follwing into HTML Expression:
    <span class="#BKG_CLASS#">#THE_COLUMN_I_WANT_TO_SHOW#</span>
    That means you would not query a plain color, but some name that can act as a CSS marker, like
    select THE_COLUMN_I_WANT_TO_SHOW
          , case when THE_COLUMN_I_WANT_TO_SHOW > 100 then 'hotColor' else 'coldColor' end as BKG_CLASS
      from my_tableIn the page's Function and Global Variable Declaration, you'd enter
    function colorMyReport () {
      apex.jQuery('.hotColor').closest('td').css('background-color','#FAA');
    }And under Execute when Page Loads, you enter:
    colorMyReport();There's only one challenge, of course, when the report is paged via AJAX, because the script would only run once (on the first page shown).
    But if this is a solution for you, I'd be pleased to show you how to overcome this. Just let me know.
    Hope there is no typo in my typing, because I have to catch my train now :-)
    Bye!

  • Retrieving column value from multiselect managed metadata column and updating metadat column in list.

    I have Library having metadata column when a document is uploaded i need update another list with metadata column of
    library in list.I have an event reciever to do that,Code is given below
    public override void ItemUpdated(SPItemEventProperties properties)
                base.ItemUpdated(properties);
                    SPList saList = properties.Web.Lists["mylist"];
                    SPListItem item = saList.AddItem();
                    item["Department"] = properties.ListItem["Department"].ToString();
                    EventFiringEnabled = false;
                    item.Update();
                    EventFiringEnabled = true;   
    my elements.xml file is as below
    <?xml version="1.0" encoding="utf-8"?>
    <Elements xmlns="http://schemas.microsoft.com/sharepoint/">
      <Receivers ListUrl="Documents">
          <Receiver>
            <Name>DocumentItemUpdated</Name>
            <Type> ItemUpdated</Type>
            <Assembly>$SharePoint.Project.AssemblyFullName$</Assembly>
            <Class>MyDocuments.Documents.Documents</Class>
            <SequenceNumber>10000</SequenceNumber>
          </Receiver>
      </Receivers>
    </Elements>
    but i did not see the the List column getting updated.But when i use the code to update a column of single line of text
    it works fine.But when i do it for multi select metadata column in debug mode i could see its giving null value even though Library had column value.
    Any pointers on how to update Multiselect metadata column programatically on itemeadding event in library to a list will
    be helpful.

    You need to use the TaxonomyFieldValueCollection class. The following code is from SP2010 but should still apply in SP2013. It is an example of updating multivalued taxonomy fields.
    public static void SetListItemMultiMetaDataColumn(Int32 id)
    using (SPSite site = new SPSite("http://basesmc2008"))
    using (SPWeb web = site.OpenWeb())
    TermSet termSet = null;
    TaxonomySession txs = new TaxonomySession(site);
    SPList list = web.Lists["Shared Documents"] as SPList;
    SPListItem item = list.GetItemById(id);
    TaxonomyField field = item.Fields["multimanage"] as TaxonomyField;
    if (field != null)
    termSet = txs.DefaultSiteCollectionTermStore.GetTermSet(field.TermSetId);
    Term term = termSet.GetTerms("sts", false).FirstOrDefault();
    if (field.AllowMultipleValues)
    TaxonomyFieldValueCollection currentCollection = item[field.Id] as TaxonomyFieldValueCollection;
    TaxonomyFieldValue tfv = new TaxonomyFieldValue(field);
    tfv.TermGuid = term.Id.ToString();
    tfv.Label = term.GetPath();
    tfv.WssId = TaxonomyField.GetWssIdsOfTerm(site, txs.DefaultSiteCollectionTermStore.Id, termSet.Id, term.Id, false, 1).First();
    currentCollection.Add(tfv);
    field.SetFieldValue(item, currentCollection);
    item.Update();
    Blog |SharePoint Field Notes Dev Tool |
    SPFastDeploy

  • Split one column  value and insert into multiple columns

    hi
    am new to plsql .
    i want to split a characters from one column and insert into multiple columns
    i tried used substr function the symbol ',' vary his place dynamically ,so i can't apply substr function.
    for eg:  before split
    col1 :
    col2 :
    col3 :
    col4 :
    colu5: adsdf,fgrty,erfth,oiunth,okujt
    after split
    col1 :adsd
    col2 :fgrty
    col3 :erfth
    col4 :oiunth
    col5 : adsdf,fgrty,erfth,oiunth,okujt
    can anyone help me
    thanks
    Edited by: 800324 on Dec 23, 2010 8:28 AM
    Edited by: 800324 on Dec 23, 2010 8:36 AM

    How about:
    SQL> create table t
      2  (col1 varchar2(30)
      3  ,col2 varchar2(30)
      4  ,col3 varchar2(30)
      5  ,col4 varchar2(30)
      6  ,col5 varchar2(30)
      7  );
    Table created.
    SQL> insert into t (col5) values ('adsdf,fgrty,erfth,oiunth,okujt');
    1 row created.
    SQL> insert into t (col5) values ('x,y');
    1 row created.
    SQL> insert into t (col5) values ('a,b,c,d');
    1 row created.
    SQL> select * from t;
    COL1                           COL2                           COL3                           COL4                           COL5
                                                                                                                                adsdf,fgrty,erfth,oiunth,okujt
                                                                                                                                x,y
                                                                                                                                a,b,c,d
    3 rows selected.
    SQL>
    SQL> merge into t a
      2  using ( with t1 as ( select col5||',' col5
      3                       from   t
      4                     )
      5          select substr(col5, 1, instr(col5, ',', 1, 1)-1) col1
      6          ,      substr(col5, instr(col5, ',', 1, 1)+1, instr(col5, ',', 1, 2)- instr(col5, ',', 1, 1)-1) col2
      7          ,      substr(col5, instr(col5, ',', 1, 2)+1, instr(col5, ',', 1, 3)- instr(col5, ',', 1, 2)-1) col3
      8          ,      substr(col5, instr(col5, ',', 1, 3)+1, instr(col5, ',', 1, 4)- instr(col5, ',', 1, 3)-1) col4
      9          ,      rtrim(col5, ',') col5
    10          from   t1
    11        ) b
    12  on ( a.col5 = b.col5 )
    13  when matched then update set a.col1 = b.col1
    14                             , a.col2 = b.col2
    15                             , a.col3 = b.col3
    16                             , a.col4 = b.col4
    17  when not matched then insert (a.col1) values (null);
    3 rows merged.
    SQL> select * from t;
    COL1                           COL2                           COL3                           COL4                           COL5
    adsdf                          fgrty                          erfth                          oiunth                         adsdf,fgrty,erfth,oiunth,okujt
    x                              y                                                                                            x,y
    a                              b                              c                              d                              a,b,c,d
    3 rows selected.
    SQL> Assuming you're on 9i...

  • Excel source multiple column values to oledb destination single column in ssis 2012

    Excel sheet has 4 columns which is filled with data till 500 rows on each column. I want to insert those excel data into single column(PolicyIds) and am using oledb destination. In excel souce i dont hav any column header. Can anyone suggest me how can i do
    this effectively. (May be i can use script task to get range of data and use it as SQL variable). Is there any best approaches.
    Sample excel
    A          B             C             D
    1001     1005       1009        1013
    1002     1006       1010        1014
    1003     1007       1011        1015
    1004     1008       1012        1016

    Inside Excel Source, use Data Access Mode - SQL Command as below:
    select F1 from [Sheet1$] where F1 is not null
    union all
    select F2 from [Sheet1$] where F2 is not null
    union all
    select F3 from [Sheet1$] where F3 is not null
    union all
    select F4 from [Sheet1$] where F4 is not null
    -Vaibhav Chaudhari

  • Display column value as column name

    Hi,
    I have a requirement to display column names as column values and vice versa. Pls suggest how to do this.
    Test data
    create table oratest as select 'saurabh' "name",23 "age" from dual;
    SQL> select * from oratest;
    name           age
    saurabh         23Expected output
    saurabh         23
    name           age

    Ok, I've only got 10g here at the minute, so this is what I'd do...
    SQL> ed
    Wrote file afiedt.buf
      1  DECLARE
      2    v_v_val     VARCHAR2(4000);
      3    v_n_val     NUMBER;
      4    v_d_val     DATE;
      5    v_ret       NUMBER;
      6    c           NUMBER;
      7    d           NUMBER;
      8    col_cnt     INTEGER;
      9    f           BOOLEAN;
    10    rec_tab     DBMS_SQL.DESC_TAB;
    11    col_num     NUMBER;
    12    v_rowcount  NUMBER := 0;
    13    v_name      VARCHAR2(20);
    14    v_age       NUMBER;
    15    v_sql       VARCHAR2(4000);
    16    v_str       VARCHAR2(250);
    17    v_und       VARCHAR2(250);
    18  BEGIN
    19    select "name", "age"
    20    into   v_name, v_age
    21    from   oratest;
    22    v_sql := 'SELECT ''name'' as "'||v_name||'", ''age'' as "'||v_age||'" from dual';
    23    c := DBMS_SQL.OPEN_CURSOR;
    24    DBMS_SQL.PARSE(c, v_sql, DBMS_SQL.NATIVE);
    25    d := DBMS_SQL.EXECUTE(c);
    26    DBMS_SQL.DESCRIBE_COLUMNS(c, col_cnt, rec_tab);
    27    --
    28    -- Bind local return variables to the various columns based on their types
    29    FOR j in 1..col_cnt
    30    LOOP
    31      CASE rec_tab(j).col_type
    32        WHEN 1 THEN DBMS_SQL.DEFINE_COLUMN(c,j,v_v_val,2000); -- Varchar2
    33        WHEN 2 THEN DBMS_SQL.DEFINE_COLUMN(c,j,v_n_val);      -- Number
    34        WHEN 12 THEN DBMS_SQL.DEFINE_COLUMN(c,j,v_d_val);     -- Date
    35      ELSE
    36        DBMS_SQL.DEFINE_COLUMN(c,j,v_v_val,2000);  -- Any other type return as varchar2
    37      END CASE;
    38    END LOOP;
    39    -- Display the header
    40    FOR j in 1..col_cnt
    41    LOOP
    42      v_str := v_str || rpad(rec_tab(j).col_name,30,' ')||' ';
    43      v_und := v_und || rpad('-',30,'-')||' ';
    44    END LOOP;
    45    v_str := rtrim(v_str);
    46    v_und := rtrim(v_und);
    47    DBMS_OUTPUT.PUT_LINE(v_str);
    48    DBMS_OUTPUT.PUT_LINE(v_und);
    49    --
    50    -- This part outputs the DATA
    51    v_str := '';
    52    LOOP
    53      v_ret := DBMS_SQL.FETCH_ROWS(c);
    54      EXIT WHEN v_ret = 0;
    55      v_rowcount := v_rowcount + 1;
    56      FOR j in 1..col_cnt
    57      LOOP
    58        CASE rec_tab(j).col_type
    59          WHEN 1  THEN DBMS_SQL.COLUMN_VALUE(c,j,v_v_val);
    60                       v_str := v_str||rpad(v_v_val,30,' ')||' ';
    61          WHEN 2  THEN DBMS_SQL.COLUMN_VALUE(c,j,v_n_val);
    62                       v_str := v_str||lpad(to_char(v_n_val,'fm999999999999'),30,' ')||' ';
    63          WHEN 12 THEN DBMS_SQL.COLUMN_VALUE(c,j,v_d_val);
    64                       v_str := v_str||rpad(to_char(v_d_val,'DD/MM/YYYY HH24:MI:SS'),30,' ')||' ';
    65        ELSE
    66          DBMS_SQL.COLUMN_VALUE(c,j,v_v_val);
    67          v_str := v_str||rpad(v_v_val,30,' ')||' ';
    68        END CASE;
    69      END LOOP;
    70      v_str := rtrim(v_str);
    71      dbms_output.put_line(v_str);
    72    END LOOP;
    73    DBMS_SQL.CLOSE_CURSOR(c);
    74* END;
    SQL> /
    saurabh                        23
    name                           age
    PL/SQL procedure successfully completed.
    SQL>Now, with 11g you can actuall create the DBMS_SQL cursor from the top part of the code...
    18  BEGIN
    19    select "name", "age"
    20    into   v_name, v_age
    21    from   oratest;
    22    v_sql := 'SELECT ''name'' as "'||v_name||'", ''age'' as "'||v_age||'" from dual';
    23    c := DBMS_SQL.OPEN_CURSOR;
    24    DBMS_SQL.PARSE(c, v_sql, DBMS_SQL.NATIVE);And using the new function in 11g's DBMS_SQL package called dbms_sql.to_refcursor and convert the DBMS_SQL cursor to a REF CURSOR which you can then use in your applications (if that's the way you need to go)...
    http://www.oracle.com/technology/oramag/oracle/07-nov/o67asktom.html
    Whatever route you take though, you won't do this simply in SQL as the column names of a query are required to be known before any data is retrieved when a query (cursor) executes. You can see that when you use the DBMS_SQL package, where the query has to be parsed and the column names and descriptions are determined before any fetching of data.

  • Hi, how can i break the value for a row and column once i have converted the image to the array?????​??

    Hi, I would like to know how can i break the value for a row and column once i have converted the image to the array. I wanted to make some modification on the element of the array at a certain position. how can i do that?
    At the moment (as per attachhment), the value of the new row and column will be inserted by the user. But now, I want to do some coding that will automatically insert the new value of the row and the column ( I will use the formula node for the programming). But the question now, I don't know how to split the row and the column. Is it the value of i in the 'for loop'? I've  tried to link the 'i' to the input of the 'replace subset array icon' , but i'm unable to do it as i got some error.
    Please help me!
    For your information, I'm using LABView 7.0.

    Hi,
    Thanks for your reply.Sorry for the confusion.
    I manage to change the array element by changing the row and column value. But, what i want is to allow the program to change the array element at a specified row and column value, where the new value is generated automatically by the program.
    Atatched is the diagram. I've detailed out the program . you may refer to the comments in the formula node. There are 2 arrays going into the loop. If a >3, then the program will switch to b, where if b =0, then the program will check on the value of the next element which is in the same row with b but in the next column. But if b =45, another set of checking will be done at a dufferent value of row and column.
    I hope that I have made the problem clear. Sorry if it is still confusing.
    Hope you can help me. Thank you!!!!
    Attachments:
    arrayrowncolumn2.JPG ‏64 KB

  • Using column value is it possible to find the table name in the database?

    Hi all,
    using column value is it possible to find the table name in the database?
    guys i need the table value
    Note:
    oracle-9i
    for example:
    i don't know NIC(column value) in which table in the database.
    Thank you,
    with regards,
    JP.
    Edited by: Guest on Feb 27, 2012 5:42 AM

    Hi,
    As far as I understand what you are asking for I would suggest 4 data dictionaries that will help you to know the table name from the column names
    1. USER_TAB_COLS
    2. ALL_TAB_COLS
    3. DBA_TAB_COLS
    4. COLS
    These can give you detail information about the columns and respective tables at user, schema, dba level. Further information on the table can be found by querying ALL_OBJECTS table giving table_name as Object_name, or you can join the data dictionaries too.
    To know about various data dictionaries avalible in Oracle please query select * from cat;
    Let us know if you need further assistance.
    Twinkle

  • Powershell Script - Convert Managed Metadata column Value to string

    HI,
    I have written a small PowerShell Script to pull records from a SP List and put them in a csv file. Here is the script:
    $MyWeb = Get-SPWeb "http://dev-apps:8800/applications/PA"
    $MyList = $MyWeb.Lists["Alist"]
    $exportlist = @()
    $Mylist.Items | foreach {
    $obj = New-Object PSObject -Property @{
    “PName” = $_["Port Name"]
    "AName" = $_["Agent Name"]
    "Address 1" = $_["Address 1"]
    "Address 2" = $_["Address 1"]
    "Address 3" = $_["Address 3"]
    "Address 4" = $_["Address 4"]
    $exportlist += $obj
    $exportlist | Export-Csv -path 'C:\Filename.csv'
    The script is running all right, the output file is also created, data is also correct for all columns but 1. This PName is a
    Managed metadata type column and the output values I am getting for this column are like this:
    "ERICA|a6d1e8fd-1f6b-4e09-9830-d21e35950881"
    "CLIVE|24dff17f-a1b5-4abe-ae86-57299e1e098b"
    viz. the ["Actual Value"|"its GUID"] (seems so). I do not want this GUID to be included in the result csv. Is there a way to remove it.
    P.S. Choice column values are being fetched just file.

    Try this (you'll need to add in your other properties)
    $items = New-Object psobject
    $items | Add-Member -MemberType NoteProperty -Name "AName" -value "" ;
    $items | Add-Member -MemberType NoteProperty -Name "PName" -value "" ;
    $items | Add-Member -MemberType NoteProperty -Name "Address1" -value "" ;
    $items | Add-Member -MemberType NoteProperty -Name "Address2" -value "" ;
    $items | Add-Member -MemberType NoteProperty -Name "Address3" -value "";
    $exportlist = @();
    $Mylist.Items | foreach {
    $pname = $_["PName"] -as [Microsoft.SharePoint.Taxonomy.TaxonomyFieldValue];
    $obj = $items | Select-Object *;
    $obj.AName = $_["AName"];
    $obj.PName = $pname.Label;
    $obj.Address1 = $_["Address 1"];
    $obj.Address2 = $_["Address 2"];
    $obj.Address3 = $_["Address 3"];
    $exportlist += $obj
    $exportlist | Export-Csv -path 'C:\AData.csv'
    Regards, Matthew
    MCPD | MCITP
    My Blog
    View
    Matthew Yarlett's profile
    See my webpart on the TechNet Gallery that allows administrative users to upload, crop and format user profile photos. Check it out here:
    Upload and Crop User Profile Photos

  • Querying the schema for table name with column value!

    In my schema i have 500+ tables and other objects.
    i have a column with the name BO_PRODUCT_CODE.
    I wants to know in what tables the value of BO_PRODUCT_CODE='FX03'.
    i have query the user_tab_columns which gives me the result with 90 tables having the column BO_PRODUCT_CODE.
    What is query which will give me the exact number/name of the table whose column value is FX03. ie, BO_PRODUCT_CODE='FX03'.

    Hi you can use this approach:
    BEGIN
    v_str VARCHAR2(250);
    v_count NUMBER :=0;
    DECLARE
    FOR loop_tbl IN ( SELECT DISTINCT table_name FROM USER_TAB_COLUMNS
    WHERE column_name ='BO_PRODUCT_CODE' )
    LOOP
    v_str := 'SELECT COUNT(*) FROM ' || loop_tbl.table_name || ' WHERE BO_PRODUCT_CODE=||'''' ||'FX03' || '''' '
    EXECUTE IMMEDIATE v_str INTO v_count ;
    IF v_count > 0 THEN
    DBMS_OUTPUT.PUT_LINE ('Table Name :'|| loop_tbl.table_name || ' Count :'||v_count);
    END IF;
    v_count :=0;
    END LOOP;
    EXCEPTION
    WHEN others THEN
    DBMS_OUTPUT.PUT_LINE(SQLERRM);
    END;
    Please remove if any syntax error.
    Regards

  • Convert column values into a row with a delimiter

    Hi Gurus,
    This may be a trivial question to you. I have an internal table itab with a column called plant, internal table has 'n' records, by the end of loop, I need to convert the column into a row delimited by comma into one row (one field). This needs to be dynamic without hard-coding.
    Plant
    1000
    2000
    3000
    4000
    5000 ....
    n....
    Expected result of the field:
    field1 value: 1000,2000,3000,4000,5000,...n
    Let's set a limit to the field say it can hold upto 500 chars.
    Thanks,
    GP.

    Hi,
    I've already tried this:
      ELSEIF <fs_dms_cv>-zca_cv_attr_ind = c_multiple.
      w_plant = <fs_plant_ele>-werks.
      concatenate w_string w_plant
                    into w_string separated by c_delimiter.
          IF w_end_fl = c_on.
          w_tabname = <fs_dms_cv>-dbtabname.
           ASSIGN (w_tabname) TO <fs_tabname>.
            IF sy-subrc = 0.
             ASSIGN COMPONENT <fs_dms_cv>-name_komp OF 
                STRUCTURE <fs_tabname> TO <fs_destination>.
                        IF sy-subrc = 0.
                          <fs_destination> = w_string.
                        ENDIF.
            ENDIF.
    There are 2 issues here: One is that after first plant there will be two commas inserted, after that it's consistent. Secondly the key word concatenate is against our code standards.
    Please let me know if there is any other way of doing this.
    Thanks.

  • Using PL/SQL to retrieve column names and column values

    If I have a table as follows
    Table A(
    meal varchar2(32),
    beverage varchar2(32),
    desert varchar2(32));
    and the table contains a row
    meal beverage desert
    pork chops iced tea apple crisp
    Is there a way in pl/sql to retrieve the column names along with the values. I have an object type
    DATA_DEFINITION_T AS OBJECT (
              "FIELD_NAME"          VARCHAR2(32),
              "FIELD_VALUE" VARCHAR2(32)
    I need to store the column name in field_name and the column value in field_value.
    So the result would be:
    FIELD_NAME = meal
    FIELD_VALUE = pork_chops
    FIELD_NAME = beverage
    FIELD_VALUE = iced tea
    FIELD_NAME = desert
    FIELD_VALUE = apple crisp
    Thanks in advance.

    Hi,
    try this procedure ....just create it and give the table name..the object M_DATA_TAB has the required data
    procedure l_fill_data_dict(p_table_name varchar2) is
    connection_id EXEC_SQL.CONNTYPE;
    bIsConnected BOOLEAN;
    cursorID EXEC_SQL.CURSTYPE;
    nIgn PLS_INTEGER;
    m_val VARCHAR2(40);
    m_col_name varchar2(40);
    m_col_val varchar2(240);
    m_cnt number;
    m_id number := 0;
    m_incr number := 0;
    p_sqlstr varchar2(4000);
    p_sql_cnt varchar2(4000) ;
    p_org_sql varchar2(4000);
    TYPE DATA_DEFINITION_TABS IS RECORD (
    FIELD_NAME VARCHAR2(32),
    FIELD_VALUE VARCHAR2(240));
    TYPE DATA_DEFINITION_TAB IS TABLE OF DATA_DEFINITION_TABS;
    M_DATA_TAB DATA_DEFINITION_TAB := DATA_DEFINITION_TAB();
    --m_file text_io.file_type;
    Begin
    --     m_file := text_io.fopen('c:\eg.txt','w');
         --Set default connection
    connection_id := EXEC_SQL.DEFAULT_CONNECTION;
    bIsConnected := EXEC_SQL.IS_CONNECTED;
    IF bIsConnected = FALSE THEN
         message('Connection Failed');
    RETURN;
    END IF;
    --Find the total no.of columns in the given table
    p_sql_cnt := 'Select COUNT(column_name) from user_tab_columns where table_name='''||p_table_name||''' order by column_id';
    cursorID := EXEC_SQL.OPEN_CURSOR;
    EXEC_SQL.PARSE(cursorID, p_sql_cnt, exec_sql.V7);
    EXEC_SQL.DEFINE_COLUMN(cursorID, 1, m_val,40);
    nIgn := EXEC_SQL.EXECUTE(cursorID);
    IF (EXEC_SQL.FETCH_ROWS(cursorID) > 0) THEN
         EXEC_SQL.COLUMN_VALUE(cursorID, 1, m_val);
    end if;
    EXEC_SQL.CLOSE_CURSOR(cursorID);
    --EXEC_SQL.CLOSE_CONNECTION;
    m_cnt := m_val;---column count
    ---get the column names from the user_Tab_columns and fetch the values from the given table for that column...
    For i in 1..m_cnt loop
         m_id := m_id+1;
    p_sqlstr := 'Select column_name from user_tab_columns where table_name='''||p_table_name||''' and column_id ='||m_id||' order by column_id';
    cursorID := EXEC_SQL.OPEN_CURSOR;
    EXEC_SQL.PARSE(cursorID, p_sqlstr, exec_sql.V7);
    EXEC_SQL.DEFINE_COLUMN(cursorID, 1, m_col_name,40);
    nIgn := EXEC_SQL.EXECUTE(cursorID);
    IF (EXEC_SQL.FETCH_ROWS(cursorID) > 0) THEN
         EXEC_SQL.COLUMN_VALUE(cursorID, 1, m_col_name);
    end if;
    EXEC_SQL.CLOSE_CURSOR(cursorID);
    --fetch the column value from the given table
         p_org_sql := 'select DISTINCT '||m_col_name||' from '||p_table_name;
         cursorID := EXEC_SQL.OPEN_CURSOR;
    EXEC_SQL.PARSE(cursorID, p_org_sql, exec_sql.V7);
    EXEC_SQL.DEFINE_COLUMN(cursorID, 1, m_col_val,240);
         nIgn := EXEC_SQL.EXECUTE(cursorID);
         Loop      
         nIgn := EXEC_SQL.FETCH_ROWS(cursorID);
              IF (nIgn > 0) THEN
                   EXEC_SQL.COLUMN_VALUE(connection_id, cursorID, 1, m_col_val);
    M_DATA_TAB.extend();
                   M_DATA_TAB(M_DATA_TAB.last).field_name := m_col_name;
                   M_DATA_TAB(M_DATA_TAB.last).FIELD_VALUE := m_col_val;
                   m_incr := m_incr+1;
                   -- text_io.put_line(m_file,m_col_name||'##'||m_col_val);
              else
                   exit;
              End if;
         End loop;--loop of records in the table for the given column
    EXEC_SQL.CLOSE_CURSOR(cursorID);
    End loop; ---loop of columns in the table
    --text_io.fclose(m_file);
    message('Total no. of items in the object='||m_incr);
    EXEC_SQL.CLOSE_CONNECTION;
    EXCEPTION
    When EXEC_SQL.Invalid_Connection then
         message('invalid connection');
         when EXEC_SQL.Package_Error     then
         message('pkg err');
         when EXEC_SQL.Invalid_Column_Number          then
         message('invalid col num defined');
         when others then
              MESSAGE(SQLERRM);
    End;
    Regards
    Dora
    Edited by: Dora on Sep 27, 2009 3:13 PM

  • Column values convert to a single row...

    I have to return the column values to a single row seperated by comma.
    If any null values in the column just ignore it without leaving a comma.
    below is an eg. There are three values and two NULL values in the table
    SQL> select ID from temp_fa;
    ID
             1
             2
             3
             5
    6 rows selected.
    I am expecting an output as 1,2,3,5Please help

    There is always more than one way in the Oracle world ;)
    You can use TRIM, for example (same setup as your example):
    hoek&XE>  create table t as select level col  from dual connect by level <= 6;
    Tabel is aangemaakt.
    hoek&XE> update t set col = null where col in (1,3,5);
    3 rijen zijn bijgewerkt.
    hoek&XE> select * from t;
           COL
             2
             4
             6
    6 rijen zijn geselecteerd.
    hoek&XE> select ltrim(sys_connect_by_path(col, ','), ',') output
      2  from  ( select col
      3          ,      row_number() over (order by col) rn
      4          from   t
      5        )
      6  where connect_by_isleaf=1     
      7  start with rn=1
      8  connect by rn = prior rn+1;
    OUTPUT
    2,4,6,,,
    1 rij is geselecteerd.
    hoek&XE> select trim ( both ',' from sys_connect_by_path(col, ',')) output
      2  from  ( select col
      3          ,      row_number() over (order by col) rn
      4          from   t
      5        )
      6  where connect_by_isleaf=1     
      7  start with rn=1
      8  connect by rn = prior rn+1;
    OUTPUT
    2,4,6
    1 rij is geselecteerd.

  • Combine 2 Column Values in One Prompt - - - - Urgent

    Hi Experts,
    I'm Using Obiee10g.
    I have a requirement where i need to create a prompt (based on 2 column values)
    Example: Name of Prompt (Search Agency) it has following values
    Agency Type1
    Agency Type2
    Agency Subtype1
    Agency Subtype2
    Agency Type1, Agency Type2 are Major Types - Which comes from Column: Agency Type
    Agency Subtype1, Agency Subtype2 are subtypes - Which comes from Column: Agency Subtype
    I took a dummy column from subject area. Converted the Prompt to Sql Results and wrote the following condition.
    Select Agency_type from Agency where Agency Type in (Agency Type1, Agency Type2)
    union
    Select Agency_subtype from Agency Where Agency subtype in (Agency Subtype1, Agency Subtype2)
    Now, My Prompt is showing correct values.
    And, My Report has following columns: Agency Id, Agency Name, Agency Type, Agency Subtype (Agency Type is prompted or Agency Subtype is prompted)
    Now, My Prompt and Report not reflects properly as i need to use multi select for prompts
    If, i'm using drop down and storing the values in presentation variable and saying that
    Agency Type = pv1 (Presen. variable1) default a
    or
    Agency Subtype = pv1 (presen. variable1) default a
    Then, it works.
    But, I need Multi select prompt. And, i cannot use p.v for multi select.
    How to acheive the above functionality.
    Experts, Please guide me.....

    If I'm Using And Condition it fails.
    Because,
    Say I have Types as - Type1, Type2
    Say I have Subtypes as - Subtype1, subtype2, subtype3
    Type table
    Type1, subtype1
    Type1, subtype2
    Type2, Subtype3
    Now, if select prompt1 ( Prompt1 is prompted -> Type1 is prompted) ----> My report reflects for type1
    if I Select prompt2 (Prompt2 is prompted -> Subtype3 is prompted) -----> My Report reflects for subtype3
    If i use here And ----> it fails ( Type = Type1 and Subtype = Subtype3)
    It should be Or ----> (Type = Type1 or Subtype = Subtype3) ----> this passes only when i select both values. But, my requirement is it should pass for even one selection.
    It can be done for drill down and pres. variable. But, my requ. is multiselect.

  • Need percentage of values used in an identity column

    Hi All,
    I am very thankful to all of you for the supprt provided at all times.
    I am asked to provide the following details about an identity column for a table:
    - Database name
    - Table name
    - Identity column
    - Used number of identity values(max of identity values)
    - Percentage of used values
    - Next identity value to be generated
    - Remaining identity value
    I was able to get all these information from the global variables in sybase and with some calculations I was able to find all the identity related information as well but it takes time. For istance, the max of the column need to be found before calculating the percentage of used identity values. Since, these tables are huge(smallest table is 95 GB - bad design) the max computation itself takes time. Our Senior production DBA was able to get it with some system stored procedure which he doesn't want to disclose to us. We have requested him to at least guide us in the right direction but we are going nowhere.
    I checked all the sybase documentation but did not get much help.
    I sincerely request everyone to suggest me the most efficient and simple way to retrieve all this information.
    Sybase ASE version is 12.5.3
    Identity column
    precision - 12
    scale - 0
    Table size is 95 GB
    Table has a  unique clustered index on five column and the identity column is one among them.
    Please let me know if any information is required.
    Thanks a lot in advance.
    Regards
    Nanda Kumar K

    Try this bit of SQL code.  Basicallly it leverages the "next_identity" function to determine which value is next to occur for the column and computes the other derived values from that.  This also assumes that identity values are uniformly used (ie, no gaps).  That's a big assumption but it seems built-in to your question.
    select "dbname"=db_name()
          ,"tablename"=so.name
          ,"identcol"=sc.name
          ,"usedvals"=convert(int,next_identity(so.name)) - 1
          ,"pctused"=str(100.00 *
                        ((convert(int,next_identity(so.name)) - 1))
                            / convert(numeric(32),power(convert(numeric(32),10),sc.prec)-1)
                        ,6,2)
          ,"nextident"=next_identity(so.name)
          ,"remainident"=convert(numeric(32),power(convert(numeric(32),10),sc.prec)-1) - convert(int,next_identity(so.name)) + 1
    from  sysobjects so
        inner join
          syscolumns sc
          on so.id = sc.id
    where so.sysstat2 & 64 = 64 -- table has identity column
    and  sc.status & 128 = 128  -- column is an identity column
    order by so.name 

Maybe you are looking for

  • Clearing out user entered variables

    I have a BI 7.0 query that displays materials that have not moved in 'X' number of days. 1. My variable screen shows "No movements since <blank>". The user enters a number in this variable (ZV_NUM_DAYS)     e.g. 90. 2. I created a variable (not ready

  • How to modify fbz5 standard program output form

    Hi friends           I need to modify the output print form of the standard program  FBZ5 how to modify it. where is the driver program for this form.

  • Error when attempting to download pl/sql script in Editor

    Greetings, I'm getting the following error: ORA-06502: PL/SQL: numeric or value error: character string buffer too small when clicking the download button located within the script editor. and ... while i've got your attention, why dont the cut and p

  • Static used on global variable declaration

    I have inherited a CVI project that contains a single .C file and a couple of .UIR files with their associated .H files. Many of the global variables have STATIC in their declaration - I believe this is due to the fact the original developer original

  • Dead iSight. Will ANY DV camcorder work?

    My iSight died. And at $164.89 to repair, I'm really giving serious consideration to shelling out a few extra dollars and just going with a firewire DV camcorder. I know they have the obvious drawbacks of size and complexity (but I can also make vide