Identifying the column match from an in clause

Greetings all,
I have a dynamic query which populates a pseudo lookup table. It can (currently) populated anywhere from 1 to 8 columns, with an associated description.
Joining to the results of this query I have a table containing a list of accounts. These accounts have two identifiers I can use to join the appropriate row in my dynamically fed lookup table. The first of these identifiers always appears in one column,
but the second can match any of the other columns.
the join looks like this:
inner join lookup
on PLID = PLID
and CV in (level0,level1,level2,level3...)
Not only would I like to clean up this join, but I also need to know which of the columns CV has matched too.
My first through was a case statement, but that would require me to know how many columns the dynamic table has, and adjust the query to reflect that each time.
case
when cv = level1 then 1
when cv = level2 then 2
end
So, my question is, does anyone have a nifty trick to solve either, or both of these problems?
Many thanks in advance.

Now that you understand the problem, perhaps we can get back to the original question of determining which values from an in operation was the match, where the values of the in are dynamic?
No, I don't yet understand the problem fully.
And there is nothing strange in this. Many of the problems we have to solve are complex, and it may be difficult to convey all information to a total stranger who have no information about business rules etc.
Particularly I don't know why think you need a dynamic result set. What I do know from experience is that working with something like a dynamic result set is painful, and that T-SQL is not intended for it. Therefore I tend to avoid solutions which produces
such beasts. And I really have to work with then, I do that client-side, and not in SQL.
There simply are no nice solutions to what you asked you for in your initial post. Therefore my advice was to reconsider what you have this far. I'm sorry if you found that advice rude.
What possibly may work in your case is that rather than having an unknown number of column, is to store all values in a string where each value takes up the same amount of space. (That is, you pad all ids or whatever you have.) Now you can use charindex
to see if you get a match, and where the match is.
Erland Sommarskog, SQL Server MVP, [email protected]

Similar Messages

  • Query the column names from Public database links

    Greetings,
    I would like to retrieve the list of all the column names from a public database link. A regular ALL_TAB_COLUMNS doesn't seem to be working.
    Thanks
    John9569

    Hi,
    I think your DBA needed to create a synonym for you to have access of that remote database view.
    CREATE SYNONYM synonym_name
    FOR view_name@db_link;Then you can find the column names by
    DESC   synonym_nameGuru's , please correct me If I am wrong.
    Thanks
    Edited by: user10679113 on Mar 12, 2009 12:28 PM
    Edited by: user10679113 on Mar 12, 2009 12:33 PM

  • How to identify the best match Business Content CUBEs

    Hi Experts
    I got the reporting requirments from the user...
    How can i identify is there any suitable business content bw objects (Data Source,DSO,Cube..etc) avaliable that i can use to meet the requirment or
    alteast find a nearst match so that i can enhance
    Please advise me how to start
    Thanks

    Hi,
    Once you collected requirements then you can take a look at the business content site for the datasources or cubes etc.which fit with your requirements.If you tell your requirements then we can suggest you what to use or you can start taking a look at  the link below.
    http://help.sap.com/saphelp_nw70/helpdata/en/3d/5fb13cd0500255e10000000a114084/frameset.htm
    Regards.

  • How can we change the column sequence from 1st to 7th position

    Hi
    I have a table in which I have a column naming DNAME and it is is on the first position I want to change its position to 7 that is the last one. The table is huge filled with data.
    Is there ant way in which I can cange the position of the column with out recreating in into another table and then renaming it.
    Thanks

    Hello,
    The sequence of a column in a table is meaningless and you should treat it as such. The column ordering you see when you run a "select * from ..." query is based on the physical implementation of the table, which is completely separate from the logical interpretation, and should not be relied on in a programmatic context. It should essentially be viewed as "random" and prone to change with the physical storage properties of the table (although this is not always the case, there is no assurance of this).
    One way to do this (which happens to be the easiest and least resource-intensive in this case) is to create a view (derived relation) of the base table, with the columns ordered in the specific sequence you desire. But really, the column ordering here is still meaningless, and the only time your application should rely on the order is when you specifically list the columns you require in a query -- but NEVER a "select *".
    cheers,
    Anthony

  • Need to change the column constrain from NOT NULL to NULL

    Hi,
    My requriment is I have to change the column constraint (NOT NULL) to NULLable (column having data), I used below query for that
    alter table table_name modify transaction_cost2 default null
    even command is successfull, but column constrain is still NOT NULL.
    can you any one help on this.. ( steps to change column constain from not null to null)
    Thanks,

    ALTER TABLE table_name
      MODIFY( transaction_cost2 NUMBER NULL )That assumes that the data type of the TRANSACTION_COST2 column is NUMBER-- you'll want to use the current data type if it is something else. I'm hoping that the fact that you have a column named TRANSACTION_COST2 doesn't imply that you have an incorrectly normalized data model. But the name of the column certainly implies that you do.
    Justin

  • Finding the column names from a table.

    I am on 10g
    I would like to find out the columns of a table where there are null columns in a table.....this table contains about 300 + columns where i do not want to put where condition for all the columns
    is there a way i can write a sql to find?
    for a given table or the results set that i need to get, i will have same results for all the rows, so it
    cant be like col1 is null on row1, but col2 is not null on row2 ...they are all identical....
    example table, but it has 300 + cols
    F_IND     H_IND     P_IND     DMA_IND
    N     N          
    N     N          
    N     N          
    N     N          Thanks

    select count(col1), count(col2), count(col3), ...
    from your table;
    The results with 0s are null throughout the table (or the table has no rows).

  • Help to get the column names from ResultSet.

    Hi,
    I hava a ResultSet and i want the column names into a String Array.
    i wrote the code to get the column names as below,
    String s = "select Dept_No,Dept_Name from tb_dept";
    rs = statement.executeQuery(s); // ResultSet defined before
    String[] columnNames1 = null;
    ResultSetMetaData meta = rs.getMetaData ( ) ;
    for (int x = 1; x <= meta.getColumnCount(); x++)
    columnNames1[x] = meta.getColumnName(x).toString();
    but i'm getting NullPointer exception. However if i print the column names means its printing the first column name and giving NullPointer Exception at the next step.
    Can anyone help me...
    Thanks,
    Rashmy

    but rs.getRow() ll give the current roe no right?
    but we can move to the last row using last() method
    and get the row count right?
    thank you yaar.
    private int getRowCount(ResultSet resultSet){
            int total = 0;
            try{
                resultSet.afterLast();
                if(resultSet.previous()) total = resultSet.getRow();
                resultSet.beforeFirst();
            }catch(SQLException sqle){
                javax.swing.JOptionPane.showMessageDialog(null,sqle);
            return total;
        }

  • How to preserve the column headings from my playlist when I transfer the list as WAV files to a flash drive?

    I have digitized several old vinyls as WAV files and have them in my MacBook Pro in an iTunes playlist. I have arranged the list under the column headings of "Grouping", "Name", "Time", "Artist", "Album" and "Genre". When I copy the files to a flash drive by drag-and-drop, none of the headings except "Name" show up. How to preserve all of the column headings when copying the file to an external device?  Thanks - RC@gnv.

    I have the same issue when trying to sync from iTunes 11 on my MacBook to my iPhone 4 iOS6.1. I blindly did the iOS upgrade to 6.1 (more fool me) and since then have not been able to use my phone as an iPod.
    I have tried restoreing it, I ve tried restoring it to a new phone but it hasn't worked for me.
    The sync starts and the capacity bar in iTunes shows capacity including and music or films etc that are to be included in the sync and then iTunes stops the sync and nothing has been transfered. As with your experience the music is shown in iTunes under Music, under Devices as greyed out with the syncing icon (dotted circle) to the left of it.
    When I try to include photos in the sync, I also get an error msg stating the connection to the iPhone has been lost. I am trying to do the sync vis USB, so I dont why I get this error.
    I can of course download any music I've bought from Apple from my iCloud to my phone but I want to be able to put any music I want on to it like I could before on iOS5.

  • How to get the column values from a BC4J View Table in UIXML?

    I am using a default UiXML Application for Order Entry system with Orders & Order Lines & Customers. I have a uix file OrdersView1_View.uix which displays (no updateable columns) all the Orders. How do I get the column value of a selected row in a BC4J Table (example:OrdersId) when a Submit button is pressed using UIXML or Java Classes?
    I appreciate any help on this.

    Hi,
    You need to use keyStamp, an example:
    <bc4j table name="orders">
    <bc4j:keyStamp>
    <bc4j:rowKey name="key" />
    </bc4j:keyStamp>
    Furthermore, you can automatically send the selected row key using the go event handler, so in the handlers section you could send the key to an orderInfo page:
    <event name="show">
    <!-- forward to the update page, passing
    the selected key as a page property -->
    <ctrl:go name="orderInfo" redirect="true">
    <ctrl:property name="key">
    <ctrl:selection name="orders" key="key" />
    </ctrl:property>
    </ctrl:go>
    </event>

  • Identifying the completed quesies from Dynamic Views

    Hi Gurus
    How to identify the queries which has completed its execution through Dynamic tables. I am able 2 find the sql's which are fired against the database by querying the v$sql but i am unable to find which are all the sql's completed the execution.Kindly suggest me how to identify the Executed sql's in the database through V$ Views.
    Thanks a lot in advance.

    You mean queries which are running at the time on the database?
    http://asktom.oracle.com/pls/asktom/f?p=100:11:0::::P11_QUESTION_ID:497421739750
    Queries running on current database.
    SQL queries
    HTH
    Girish

  • How to get all the column values from a table source

    Hi,
    I have created one table source on a employee table and some customized attributes using global settings>search attributes.
    Now these customized attributes mapped with the table columns through attribute mapping from the sorce tab.
    Using doOracleSearch method i passed last parameter i.e. Integer array of customized attributes.
    After execution of doOracleSearch method i am getting the results but customized attributes are not coming.
    getCustomAttributes method returns null instead of some values.
    Please refer following code for more info:
    Integer[] fetchAttr=new Integer[2];
    fetchAttr[0]=new Integer(137);
    fetchAttr[1]=new Integer(138);
    result =
    stub.doOracleSearch("BTM",
    new Integer(1),
    new Integer(10),
    Boolean.TRUE,
    Boolean.TRUE,
    group,
    "en",
    "en",
    Boolean.TRUE,
    null,
    null,
    fetchAttr);
    ResultElement[] resElements = result.getResultElements();
    for(int i = 0; i < resElements.length; i++)
    System.out.println("Title : " + resElements[0].getTitle());
    System.out.println("Snippet : " + resElements[0].getSnippet());
    System.out.println("URL : " + resElements[0].getUrl());
    System.out.println("non default : " + resElements[0].getCustomAttributes()); // it returns null here
    }

    Confirm the attributes you are asking SES for match those on the data source being searched. One thing to try is to simply tell SES to return all custom attributes for your search. Here is a snippet to build a list of all attribute IDs and pass them to your search...
    // Create and set SOAP URL
    OracleSearchService searchService = new OracleSearchService();
    searchService.setSoapURL("http://myserver:7777/search/query/OracleSearch");
    // Set attributes to fetch (all)
    Attribute[] attributesAll = searchService.getAllAttributes("en");
    ArrayList<Integer> attributeIds = new ArrayList<Integer>();
    for(Attribute a: attributesAll)
    attributeIds.add(a.getId());
    Integer attributeIdArrayAll[] = new Integer[attributeIds.size()];
    attributeIdArrayAll = attributeIds.toArray(attributeIdArrayAll);      
    // Query
    OracleSearchResult result = searchService.doOracleSearch("some text", ..........[other params], attributeIdArrayAll);
    // Print out results
    ResultElement[] resElements = result.getResultElements();
    for(int i = 0; i < resElements.length; i++)
    // Get document
    ResultElement doc = resElements;
    // Print Title
    System.out.println("Title: " + doc.getTitle());
    // Print custom attributes
    CustomAttribute[] attributes = doc.getCustomAttributes();
    for(int j = 0; j < attributes.length; j++)
    CustomAttribute attr = attributes[j];
         System.out.println("[Custom Attribute] " + attr.getName() + ": " + attr.getValue());
    Hope this helps.

  • How to get the name of the column returning from reslut set

    for the below code how can i get the table B column names?
    Thank you.
    stm = con.createStatement();
    rs = stm.executeQuery("select a.title, b.* from Tbl_Questions a, Tbl_Answers b where b.id=" + answerId +" and b.questionId=a.id");
    if( rs.next() ) {
    answer.setId(answerId);
    answer.setQuestionId(rs.getString("b.questionId"));
    answer.setQuestionTitle(rs.getString("a.title"));
    answer.setTitle(rs.getString("b.title"));
    answer.setInputType(rs.getString("b.inputtype"));
    }

    Column names may be output with meta data.
    DatabaseMetaData metadata = null;
      Class.forName("oracle.jdbc.driver.OracleDriver");
      String url="jdbc:oracle:thin:@localhost:1521:ORCL";
      Connection currentConnection = DriverManager.getConnection(url,
                         "oe", "");
      metadata = currentConnection.getMetaData();
      String[] names = {"TABLE"};
      ResultSet tables = metadata.getTables(null,"%", "%", names);
      while (tables.next()) {
      String tableName = tables.getString("TABLE_NAME");
      String tableSchema = tables.getString("TABLE_SCHEM");
      String tableType = tables.getString("TABLE_TYPE");
      System.out.println("Table Name:"+tableName+ " Table Schema: "+tableSchema+ " Table Type: "+tableType);
       ResultSet columns = metadata.getColumns(null, "%", tableName, "%");
    while (columns.next()) {
      String columnName = columns.getString("COLUMN_NAME");
      String datatype = columns.getString("TYPE_NAME");
      int datasize = columns.getInt("COLUMN_SIZE");
      int nullable = columns.getInt("NULLABLE");
      System.out.println("Column Name: "+columnName+ " Data Type: "+datatype+ " Data Size: "+datasize+" Nullable: "+nullable);
        }

  • How the columns retrive from datebase when u r using joins

    Hi,
    I am Seetharamaiah.c working in Xansa India Limited. I got a doubt . Pls clarify my doubt when we r retriving the data from database, how the colums retrieve when we r using self join. What exactly internally happen.
    Thanking u,
    Seetharamaiah.C

    use set autotrace on
    SQL> set autotrace on
    SQL> select dname,ename
    from dept d,emp e
    where d.deptno = e.deptno;
    Execution Plan
    0 SELECT STATEMENT Optimizer=CHOOSE
    1 0 NESTED LOOPS
    2 1 TABLE ACCESS (FULL) OF 'EMP'
    3 1 TABLE ACCESS (BY INDEX ROWID) OF 'DEPT'
    4 3 INDEX (UNIQUE SCAN) OF 'SYS_C0063851' (UNIQUE)
    Each row of the emp table is returned and the corresponding dept row is found using the index.
    Introduce an outer join:
    select dname,ename
    from dept d,emp e
    where d.deptno = e.deptno(+)
    Execution Plan
    0 SELECT STATEMENT Optimizer=CHOOSE
    1 0 MERGE JOIN (OUTER)
    2 1 SORT (JOIN)
    3 2 TABLE ACCESS (FULL) OF 'DEPT'
    4 1 SORT (JOIN)
    5 4 TABLE ACCESS (FULL) OF 'EMP'
    and you get two full table scans with the results merged to populate the dept with no emp records

  • Making XSD element name match the column name/header

    The XML format of the answer I created looks like the following. How can I change the element name from C0, C1... to real column name? http://host:port/analytics/saw.dll?Go&searchid provided the XML
    <?xml version="1.0" encoding="utf-8" ?>
    - <RS xmlns="urn:schemas-microsoft-com:xml-analysis:rowset">
    - <xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:saw-sql="urn:saw-sql" targetNamespace="urn:schemas-microsoft-com:xml-analysis:rowset">
    - <xsd:complexType name="R">
    - <xsd:sequence>
    <xsd:element name="C0" type="xsd:double" minOccurs="0" maxOccurs="1" saw-sql:type="double" saw-sql:displayFormula=""CUSTOMERS"."SALES"" saw-sql:aggregationRule="none" saw-sql:aggregationType="nonAgg" saw-sql:tableHeading="CUSTOMERS" saw-sql:columnHeading="SALES" />
    <xsd:element name="C1" type="xsd:string" minOccurs="0" maxOccurs="1" saw-sql:type="varchar" saw-sql:displayFormula=""CUSTOMERS"."CITY"" saw-sql:aggregationRule="none" saw-sql:aggregationType="nonAgg" saw-sql:tableHeading="CUSTOMERS" saw-sql:columnHeading="CITY" />
    </xsd:sequence>
    </xsd:complexType>
    </xsd:schema>
    - <R>
    *<C0>0.3</C0>*
    *<C1>WILLITS</C1>*
    </R>
    Edited by: user732932 on Jan 7, 2010 11:38 AM

    OR is there a way to pass the column headers from OBIEE to a URL? For example, session parameters can be passed using @{parmName}

  • Export from SP list to Excel: Excel doesn't show changed colum name. It shows only the original column names, which would be done by the column creation.

    Hello,
    I have an excel list with some columns. I changed the name of some of the column. When I export this list to excel, I always get the first column name, which was created by the creation of the column, and not the new one.
    Is there some possibility to export a SP list to export with the new column names?
    I'm waiting for your help,
    BR
    Damian

    Hi Damian,
    I tested in my environment, change the column name and export to excel list, the exported field name is the correct one.
    Please check the column name from somewhere else from site UI, you could check from SharePoint designer or powershell script.
    [system.reflection.assembly]::loadwithpartialname("microsoft.sharepoint")
    $site= New-Object Microsoft.SharePoint.SPSite ("http://siteurl")
    $web=$site.OpenWeb()
    $list=$web.Lists["CustomList"]
    $list.Fields |select ID, title, internalname| more
    In addition, I wonder if the issue occurs to all lists or one specific list. If the issue only occurs to one list, please try to save this list as template and create a new list based on this list and test the issue again.
    Regards,
    Rebecca Tu
    TechNet Community Support
    Please remember to mark the replies as answers if they help, and unmark the answers if they provide no help. If you have feedback for TechNet Support, contact
    [email protected]

Maybe you are looking for

  • File Corruption During Sync Windows 8.1

    Hi I have recently introduced some Windows 8.1 systems into our environment, a Sony laptop and a non branded custom build, both systems are running Windows 8.1 Pro. Our environment is as follows: Windows Server 2008 domain PPTP VPN for laptop users u

  • Photoshop elements 13 en cadeau

    Bonjour à tous, On m'a offert le logiciel photoshop elements 13 en cadeau. Je dois maintenant le télécharger. J'ai créé mon compte Adobe et j'ai bien le numéro mais je ne vois nulle part où le télécharger, je ne peux que l'acheter. Est ce quelqu'un s

  • Receiver determination based on target msg???

    Hi All, Is it possible to do a receiver determination based on some field present in target msg. I know I can do the same if the field is present in source msg with the condition editor in receiver determination. But this will not help my scenario. I

  • PC Configurat​ion for Fast LV FPGA Compile

    What's the state-of-the-art PC for fast LV FPGA compile? My life becomes short, when I have to wait 2 hours to compile a 90% usage 5640R VI on my Dell Dimension 2.8GHz PC.  I toggled the hyper-threading on and off, it does not change too much.

  • Adobe Illustrator CS.1 funktioniert nicht mehr

    Meldung: Das Programm wird aufgrund eines Problems nicht richtig ausgeführt. Das Programm wird geschlossen und Sie werden benachrichtigt, wenn eine Lösung verfügbar ist.