Problems witth sql query from servlet

hi,
I have a servlet that accesses a MySql database to get the ID of an employee based on employee name (grabbed from session). My problem is that :
empName contains a whitespace (String empName ="abc xyz")
When I try to give this to the query:
String query ="select id from user where eName =" +empName;
Now I keep getting a "SQL syntax error:please check your syntax to use near 'xyz' at line 1." here which I think is because of the white space in the empName. ( I tried dummy empName without spaces).
How do I get around this ..I cannot keep the names in the database without any space since they are being dislpayed in other pages. I tried doing a trim() on the empName before passing it to the sql query but I keep getting the same error.
Is there any way I could query the DB with a white space in the empName?
Thanks,
G.
Is there any way to

Second of all: Use prepared statements:
like:
insertStatement = "SELECT ? FROM ? WHERE name=?";                    
stmnt = _sql_connection.prepareStatement(insertStatement);
stmnt.setString(1, "name");
stmnt.setString(2, "table");
stmnt.setString(3, "test");This is more secure. If you do it the above way i could enter some thing like
*; DROP TABLE *; --
You dont want a user to kill your whole db, dont you?
so your querry String query ="select  id from user where eName = '" +empName +"'"; will end up:
select  id from user where eName = '*'; DROP TABLE *; -- 'where everything after -- is ignored because this is a comment flag.

Similar Messages

  • Problems in SQL Query

    Dear All,
    I am having some problem in SQL query. I am trying to get total sum of one inventory using the following query it works fine:
    sum(case when mt.transaction_quantity > 0 then (mt.transaction_quantity) else 0 end) "TOT_IN"
    ,sum(case when mt.transaction_quantity >= 0 then 0 else (abs(mt.transaction_quantity)) end) "TOT_OUT"
    But when I breakup the total sum into monthly breakup it fails to return the correct some could any one help what is wrong in the following query which is returning incorrect monthly sum. Following is that query. Your help in this regard would highly be appreciated.
    sum(case when mt.transaction_quantity > 0 then (decode (floor (floor (to_date('17-MAR-2009')- mt.transaction_date) / 30), 0, mt.transaction_quantity, null)) else 0 end) "MONTH1_IN"
    ,sum(case when mt.transaction_quantity >= 0 then 0 else (decode (floor (floor (to_date('17-MAR-2009')- mt.transaction_date) / 30), 0, abs(mt.transaction_quantity), null)) end) "MONTH1_OUT"
    Thanks

    Hi,
    Sorry, I don't really understand what you want.
    Whenever you have a question, it helps to post:
    (1) The version of Oracle (and any other relevant software) you're using
    (2) A little sample data (just enough to show what the problem is) from all the relevant tables
    (3) The results you want from that data
    (4) Your best attempt so far (formatted)
    (5) The full error message (if any), including line number
    Executable SQL statements (like "CREATE TABLE AS ..." or "INSERT ..." statements) are best for (2).
    If you can present your problem using commonly available tables (for example, tables in scott schema, or views in the data dictionary), then you can omit (2).
    Formatted tabular output is okay for (3). Type these 6 characters
    {code}
    (small letters only, inside curly brackets) before and after the tabular text, to preserve spacing.
    What exactly do you mean by "monthly breakup"?
    If you want separate figures for each calendar month, Blushadow's suggestion (TRUNC (mt.transaction_date, 'MM')) is what you want.
    If you want separate figures for the last 30 days before today, then something like what you posted ("FLOOR ((:target_date - mt.transaction_date) / 30)": the extra FLOOR doesn't help any) should work, so if you ran the query on March 17, 2009, the first "month" would be February 16 through March 17.
    In a CASE statement, there's rarely any need to use DECODE. The following is equivalent to the last line of code you posted:
    ,       SUM ( CASE
                WHEN  mt.transaction_quantity >= 0
                THEN  0
                WHEN  TO_DATE ('17-MAR-2009', 'DD-MON-YYYY') - mt.transaction_date
                        BETWEEN 0
                        AND     29.99999  -- 30 days minus a fraction of a second
                THEN  ABS (mt.transaction_quantity)
               END
             )          AS month1_outDon't you find this easier to understand (and debug)?

  • Retrieve SQL Query from report without RAS.

    We have a fat client application which uses Crystal Reports.  We upgraded from the RDC/ActiveX viewer to the .Net SDK/.Net Viewer.  One feature that we miss is that we used to read the SQL Query that a report used and wrote it to our log file.  This helped with debugging and with troubleshooting problems in the field.
    Since we only deploy the freely distributable Crystal Reports model and I don't think that RAS falls into this category is there a way which we can read the SQL Query from a report?  If not, could you add this to a list of requested features for future versions.
    I understand why you removed the ability to set the SQL query, but simply reading it does add value.  Maybe it is difficult for you to return this before the report is run in which case giving us the ability to read the value after the report has been run would also be fine.
    Alternatively some sort of event that is fired each time a query is executed would also be helpful as this would allow Crystal Reports clients to monitor SQL from sub-reports.  You could even build a robust logging mechanism which could report additional information (i.e. number of rows returned, formula evaluations, or anything related to report execution).  All of this would make troubleshooting report issues easier for those of us who use Crystal Reports.

    Need to know what version of CR you are using?
    You can use InProc RAS, it comes with CR and is distributed with the runtime files.
    If you are using CR Basic or the version that comes with Visual Studio .NET then no this will not be added to that product line. It is basic functionality only. You will need to upgrade to a Developer version of Crystal reports to take advantage of the the RCAPI features as well as more general API's.
    There is logging for our DB drivers but the log files get very large. If you use ODBC then you have the option to turn on tracing also. Using RAS you don't need to turn on logging as you can get the SQL. This won't be added either.
    Thank you
    Don

  • See sql query from crystal report without crystal report

    see sql query from crystal report without crystal report 

    Hi,
    Depends on datasource type but you could have a look at ODBC trace or if you have access to the SQL Server you could use profiler to monitor the session.
    Regards,
    Craig
    And this will only be of use if you know which Server/Insstance/Database the Report is connecting to...
    Please click "Mark As Answer" if my post helped. Tony C.

  • Help with translating SQL query from SQL Server syntax to Oracle syntax

    Hi,
    is it someone that can help me translate following SQL query from SQL Server syntax to Oracle syntax.
    SELECT ID,
    [LMT(MTR)] = MAX(case when TYPE = 'LMT' then VALUE end),
    [AAD(KGM)] = MAX(case when TYPE = 'AAD' then VALUE end),
    [VOL(MTQ)] = MAX(case when TYPE = 'VOL' then VALUE end)
    FROM yourtable
    GROUP BY ID
    Your help is highly appreciated, thanks in advance.

    Like this,
    SELECT ID,
    MAX(case when TYPE = 'LMT' then VALUE end) LMT_MTR,
    MAX(case when TYPE = 'AAD' then VALUE end) AAD_KGM ,
    MAX(case when TYPE = 'VOL' then VALUE end) VOL_MTQ
    FROM yourtable
    GROUP BY ID-Arun

  • How to transport SQL Query from SQVI Tcode?

    Dear Friends,
    Can any one tell me how to transport SQL Query from <b>SQVI</b> Tcode.
    Full Points will be rewarded.
    Thanks & Reagrds
    Ravi

    go to sqvi tool .....
    select u r query name ......in the menubar ....quickview....> additianal functions.......>generate program
    after doing generate program ....go to again same menu path as i have mentioned above [quickview....> additianal functions.......>display report name it will give the report name of the select query ..........copy the report name and give it abap editor[se38] u will get u r query program......with all authority checks.....
    in start of selection event of u r program u will find u r select query.
    reward points if helpful

  • Problem with SQL Query

    I am a java developer and having problem writing a simple sql query. Any help is highly appreciated.
    USER_LOGIN
    CREATE TABLE USER_LOGIN
    EMAIL_ADDRESS VARCHAR2(30 BYTE) NOT NULL,
    PASSWORD VARCHAR2(30 BYTE) NOT NULL,
    LAST_NAME VARCHAR2(20 BYTE),
    FIRST_NAME VARCHAR2(20 BYTE),
    STATUS VARCHAR2(1 BYTE)
    DATA:
    INSERT INTO USER_LOGIN (EMAIL_ADDRESS, PASSWORD, LAST_NAME, FIRST_NAME, STATUS) VALUES ( [email protected], UjBhZHJ1bm5lcg==, klein, james, 1);
    INSERT INTO USER_LOGIN (EMAIL_ADDRESS, PASSWORD, LAST_NAME, FIRST_NAME, STATUS) VALUES ( [email protected], UjBhZHJ1bm5lcg==, cullen, sarah, 1);
    INSERT INTO USER_LOGIN (EMAIL_ADDRESS, PASSWORD, LAST_NAME, FIRST_NAME, STATUS) VALUES ( [email protected], UjBhZHJ1bm5lcg==, cole, kling, 1);
    INSERT INTO USER_LOGIN (EMAIL_ADDRESS, PASSWORD, LAST_NAME, FIRST_NAME, STATUS) VALUES ( [email protected], UjBhZHJ1bm5lcg==, stein, amy, 1);
    INSERT INTO USER_LOGIN (EMAIL_ADDRESS, PASSWORD, LAST_NAME, FIRST_NAME, STATUS) VALUES ( [email protected], UjBhZHJ1bm5lcg==, stone, edward, 1);
    INSERT INTO USER_LOGIN (EMAIL_ADDRESS, PASSWORD, LAST_NAME, FIRST_NAME, STATUS) VALUES ( [email protected], UjBhZHJ1bm5lcg==, simps, harris, 1);
    INSERT INTO USER_LOGIN (EMAIL_ADDRESS, PASSWORD, LAST_NAME, FIRST_NAME, STATUS) VALUES ( [email protected], UjBhZHJ1bm5lcg==, brown, steven, 1);
    INSERT INTO USER_LOGIN (EMAIL_ADDRESS, PASSWORD, LAST_NAME, FIRST_NAME, STATUS) VALUES ( [email protected], UjBhZHJ1bm5lcg==, kumar, vikram, 1);
    INSERT INTO USER_LOGIN (EMAIL_ADDRESS, PASSWORD, LAST_NAME, FIRST_NAME, STATUS) VALUES ( [email protected], UjBhZHJ1bm5lcg==, gray, susan, 1);
    INSERT INTO USER_LOGIN (EMAIL_ADDRESS, PASSWORD, LAST_NAME, FIRST_NAME, STATUS) VALUES ( [email protected], UjBhZHJ1bm5lcg==, green, monica, 1);
    INSERT INTO USER_LOGIN (EMAIL_ADDRESS, PASSWORD, LAST_NAME, FIRST_NAME, STATUS) VALUES ( [email protected], UjBhZHJ1bm5lcg==, tile, eric, 1);
    INSERT INTO USER_LOGIN (EMAIL_ADDRESS, PASSWORD, LAST_NAME, FIRST_NAME, STATUS) VALUES ( [email protected], UjBhZHJ1bm5lcg==, parder, sergey, 1);
    INSERT INTO USER_LOGIN (EMAIL_ADDRESS, PASSWORD, LAST_NAME, FIRST_NAME, STATUS) VALUES ( [email protected], UjBhZHJ1bm5lcg==, fossil, bill, 1);
    This is just the sample data. In production I have around 30,000 records and I have a requirement to retrieve the records in a batch of 5,000 at a time.
    For testing on the above 10 records, I need to retrieve 3 at a time.
    For instance: From my java servlet phase listener, I am going to run a loop, inside which I make a database call. For the first time inside the loop, it has to fetech records 1 to 3, the second time 4 to 6, the third time 7 to 9 and finally the last record. I will be able to pass two parameters for start and end row indexes.
    I have come up with the following query...
    SELECT U.EMAIL_ADDRESS,
    U.PASSWORD,
    U.LAST_NAME,
    U.FIRST_NAME,
    U.STATUS
    FROM USER_LOGIN U
    WHERE ROWNUM > /*start index*/ AND ROWNUM < /*end index*/
    ORDER BY EMAIL_ADDRESS
    But the results are not as expected. It works well for the first batch where start index is 0 and end index is 4, but it returns zero records when start index is 3 and end index is 7. Any help on this would be highly appreciated
    Thanks.

    Saludos Sirgeneral,
    This is one of the technique you should be working on
    SELECT * FROM(
    SELECT ROWNUM rn,e.* FROM emp e
    ORDER BY empno)
    WHERE rn BETWEEN &st_range AND &end_rangeIn your case the query would be
    select * from(
    SELECT rownum en, U.EMAIL_ADDRESS,
    U.PASSWORD,
    U.LAST_NAME,
    U.FIRST_NAME,
    U.STATUS
    FROM USER_LOGIN U
    ORDER BY EMAIL_ADDRESS)
    where rn between 4 and 6); --second set for exampleCheers!!!
    Bhushan

  • JSTL : problems with sql:query /forEach  tag

    I am not able to iterate thru the resultset provided by <sql:query> tag in JSTL. rowcount and columnName works, which means that query does produce a resultset. However, the <c:forEach> tag doesnt display the retrieved data. Code is approx like:
    c:catch var="e">
    <sql:query var="queryResults" >
    select * from emp
    </sql:query>
    </c:catch>
    <c:if test="${e!=null}">The caught exception is: ${e}
    ${queryResults.rowCount} <br>
    <c:forEach var="row" items="${queryResults.rows}">
    <tr>
    <td> <c:out value="${row.EMPNO}" /></td>
    </tr>
    </c:forEach>
    </table>
    Error thrown is :
    javax.servlet.ServletException: Unable to find a value for "EMPNO" in object of class "java.lang.String" using operator "."
         org.apache.jasper.runtime.PageContextImpl.doHandlePageException(PageContextImpl.java:867)
         org.apache.jasper.runtime.PageContextImpl.handlePageException(PageContextImpl.java:800)
         org.apache.jsp.jsp.sql.query_jsp._jspService(query_jsp.java:92)
         org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:133)
         javax.servlet.http.HttpServlet.service(HttpServlet.java:856)
         org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:311)
         org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:301)
         org.apache.jasper.servlet.JspServlet.service(JspServlet.java:248)
         javax.servlet.http.HttpServlet.service(HttpServlet.java:856)
    Pls. help!

    Thanks a lot all. My problem was solved by simply replacing the taglib directive
    <%@ taglib uri="http://java.sun.com/jstl/core" prefix="c" %>
    to
    <%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
    Cheers!

  • Problem with SQL query region source containing OLAP clauses

    Hi team,
    I believe I found a bug when HTMLDB validates the SQL Query in a report region.
    My query includes an ORDER BY clause within a windowing function and HTMLDB refuses to accept the source owing to the presence of the ORDER BY and the column heading sort preference.
    Clearly the order-by in a window function has little to do with the column heading sort, but this error prevents me from updating the conditional display item in the page definition.
    Note also that the page was imported smoothly from the 1.5 version, so probably the region source is not checked at that time, but only when you update it "manually".
    So, in the end, if I don't change anything the page works because the sql query is assumed to be correct but unfortunately I need to change the condition and I cannot.
    The problem shows up in page 126 of app 21670, SQL query region.
    Bye,
    Flavio
    PS: may be I can work around this by using the pl/sql function returning the sql query.

    Flavio,
    We're aware of this problem. For now, your workaround is described in this thread:
    HTMLDB 1.6 and "order by" in analytic functions
    Sergio

  • Problem in sql query because of order by clause

    Hi All,
    I am facing a one problem in my one sql query.I am using Oracle 10gR2.
    Query is given below:
    SELECT t1.ename
            FROM T1, T2
           WHERE T1.EMPNO = 1234
             AND T1.ACCOUNTNO = T2.ACCOUNTNO
             AND T1.SEQ = T2.SEQ
           ORDER BY T2.SEQThe Plan of the query is :
    | Id  | Operation                     | Name                 | Rows  | Bytes | Cost (%CPU)| Time     |
    |   0 | SELECT STATEMENT              |                      |     2 |   218 | 11716   (1)| 00:00:41 |
    |*  1 |  TABLE ACCESS BY INDEX ROWID  | T1                   |     1 |    89 |     1   (0)| 00:00:01 |
    |   2 |   NESTED LOOPS                |                      |     2 |   218 | 11716   (1)| 00:00:41 |
    |*  3 |    TABLE ACCESS BY INDEX ROWID| T2                   |     2 |    40 | 11715   (1)| 00:00:41 |
    |   4 |     INDEX FULL SCAN           | PK_T2_SEQ            | 58752 |       |   122   (5)| 00:00:01 |
    |*  5 |    INDEX RANGE SCAN           | FK_ACCOUNTNO         |     3 |       |     0   (0)| 00:00:01 |
    ----------------------------------------------------------------------------------------------------Now i want to reduce the time of this query.
    If i am removing Order by clause from query than performance of the query is totally perfect but with order by clause its taking a time.
    I have already set SORT_AREA_SIZE but still nothing is improving.
    Welcome and thanks for your suggestions.
    Thanks,
    Edited by: BluShadow on 23-Jun-2011 07:55
    added {noformat}{noformat} tags and formatted explain plan to make it readable.  Please see {message:id=9360002} for details on how to post code and data                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                           

    Hi,
    There are a couple of things I do not understand.
    1. Why don't you put {noformat}{noformat} around your code, it makes it so much easier to read, especially your explain plan
    2. You claim that the ORDER BY is problematic compared to no order by. Then why do you choose to post only one plan?
    3. It is hard to understand how your tables relate, and which indexes you have and which you don't.
    - PK_T2_SEQ, does this mean that SEQ alone is primary key of T2?
    - If SEQ is primary key of T2, why do you join on accountno, seq and not just seq?
    - If SEQ is primary key of T2 one of the tables is denormalized.
    4. FK_ACCOUNTNO, is this an index on accountno, alone?
    - Or is this AccountNo, Seq?
    5. Is there no index on T1.EMPNO?
    Above could of course just be a case of my not understanding the names of your indexes.
    So, here are my guesses:
    Above plan is for the ORDER BY query. That means the optimizer, has chosen to full scan PK_T2_SEQ, since data is then read according to the ORDER BY.
    (This could be a bad choice)I
    You could try and order by t1.seq, instead. Result should be the same.
    Regards
    Peter                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                               

  • Sql query from Oracle/Hyperion

    Hi, guys. my problem is:
    My work environment is windows 2003 server sp2 on both servers, to have a Hyperion System 9.2 and the other Hyperion System 9.3.1. I have an Oracle ODBC server to fetch data.
    When you load data from an Oracle database (version 9.2.0.5) to an Essbase cube through a rule file sql Hyperion System with version 9.2 everything works fine, I am all the necessary information. But when I try to do the same (in another server, version 9.3.1 Hyperion System) with the sql query does not do well. What is the problem. the bag is a bad version or set the ODBC
    please help me
    Thank you very much.
    Alberto.

    without knowing more information, I'm going to guess the probem is with the ODBC driver. Try using the SQL in a tool like toad to use the ODBC to query the data. That will tell you if it is an ODBC issue or not.

  • VERY URGENT: problem in sql query with long datatype in weblogic

    I have a problem while tryind to retrieve a column value with a long datatype using servlet and oci driver and the server is weblogic5.1 .I have used prepared statement the problem comes in the
    preparedStatement.executeQuery().
    The sql Query is simple query and runs well in all cases and fails only when the long datatype column is included in the query.
    The exception that comes on the weblogic server is that :
    AN UNEXPECTED EXCEPTION DETECTED IN THE NATIVE CODE OUTSIDE THE VM.

    Did you try changing the driver then?
    Please use Oracle's thin driver instead of the oci driver.
    There are many advantages of using the type 4 driver. the first and foremost being that it does not require oracle client side software on your machine. Therefore no enteries to be made in tnsnames.ora
    The thin driver is available in a jar called classes112.zip the class which implements the thin driver is oracle.jdbc.driver.OracleDriver
    the connection string is
    jdbc:oracle:thin:@<machine name>:1521:<sid>
    please try out with the thin driver and let me know.
    regards,
    Abhishek.

  • Problems with sql query in azure

    Hi!
    I follow the tutorial "Add Mobile Services to an existing app" and when I came to the last step:"View the data stored in the SQL Database I got problems. When I write the Query "SELECT * FROM [todolist-2597].[todoitems] and then click
    'Run', it doesn't work. I have tried to change the syntax but nothing work. 'todolist-2597' is the name of my database, which I use in two different mobileservices. I Believe that the name of my datatable is todoitems, but I'm no sure. I tried the Spelling
    'TodoItems', but this doesn't work either. So what might be the problem? Anyone who have an idea?
    Greetings from a beginner in Sweden.

    Hi,
    Assuming your database and table name are correct this query should just run fine. Are you running the query from within the online SQL Azure Management Portal? If so, you can also the see the exact table name from there. Does it match the name used
    in your query?
    You can also grab the connectionstring for your database from the Azure Portal and use that to connect to your database from SQL Management Studio.
    Can you validate your database and table names?
    Edward

  • Problem use SQL query in coding report with SBO

    Hi everyone!
    I have problem in execute query to delete and create a report with SQL 2000 in SAP.
    Try
            oForm.DataSources.DataTables.Item(0).ExecuteQuery("DELETE FROM rptReport")
    Catch ex As Exception
    End Try
             oForm.DataSources.DataTables.Add("TestReport")
             oForm.DataSources.DataTables.Item(0).ExecuteQuery("SELECT     Number, RefDate, Memo        into  rptReport   FROM         dbo.OJDT")
             oTable = oForm.DataSources.DataTables.Item("TestReport")
    This code is error. I don't know how to execute 2 this sql command. Hope everyone help me hix hix!  .

    /Invalid query tree  [300-33]. The SQL error is 8180/
    But search in SQL book hasn't got that err. Some person spoke ExecuteQuery property wasn't support Table Delete and Create, it only support simple Select... I tried to use Recordset but don't success. Can I use "Delete" and "Select ... Into..."   query another style??? Help me, please...!!!

  • Strange problem with SQL query in toad.

    Guys,
    My colleague is up with a strange problem with an SQL query that if it is run in toad encounters the "ORA-03113: end-of-file on communication channel" problem,but if run in SQL plus executes just fine.
    Do anyone have thoughts about this strange error in toad?
    Thanks!!!!
    Regards,
    Bhagat

    Not sure what version of TOAD you have but it may have shipped with SQLMonitor which montiors SQL sent from Windows apps . Navigation should be similar to;
    Start~Programs~Quest Software~TOAD for Oracle~Tools~SQLMonitor
    or
    C:\Program Files\Quest Software\Toad for Oracle\SQLMonitor.exe
    To use it, start TOAD and connect, start SQLMonitor and click the checkbox for TOAD.exe, then execute the query. SQLMonitor will show you the actual query that TOAD sent to the client. It may be exactly what you sent or it may contain some extras.

Maybe you are looking for

  • Set isolation level in EJB 2.0

    how can i set isolation level to a transaction in EJB 2.0. If anybody can give example code much appriciated

  • Does Logic 8.0.2 work with OS 10.6.7?

    I need to upgrade my Sibelius 3.1.3 to version 7 - I currently have OS 10.4.11 but the minimum requirement is OS 10.6.7. I've just put in 8GB RAM as a start. If I get 10.6.7 I'm not sure whether Logic 8.0.2 will still work. Also wondering which other

  • Which plan is fast

    hi, i m using oracle 10g , i want to know which plan would do fast search. i have zone wise data ,around 30 zones and would have data in terabytes. so should i create partition table according to zone . or should i create 35 zone table . which plan w

  • Labview Software Manager - Hampshire UK

    Leading a team of software engineers you will take ownership of the software development process for new Test Systems for RF equipment.  Extensive experience of Labview Programming (preferably CLD level) is essential. Experience of TestStand, plus a

  • Sort a Grid while using CollapseLevel

    I'm using a Grid with data that I need sorted.  I can use the SQL statement to sort the data how I need it.  But I would also like to use CollapseLevel.  When I do that my data gets scrambled.  Have any of you found a work around for this?