Trying to use greater than in a case statement

What is the correct way to write this case statement?
Case
F.NextOrder2
> F.CutOff
Then
Else F.NextOrder2
as NextOrder3

You're missing END, e.g.
CASE when F.NextOrder2 > F.CutOff then '' else cast(F.NextOrder2 as varchar(100)) end as NextOrder3
All values in the CASE statement must be of the same data type.
See this blog post why
SQL Server Case/When Data Type problems
Premature optimization is the root of all evil in programming. (c) by Donald Knuth
Naomi Nosonovsky, Sr. Programmer-Analyst
My blog

Similar Messages

  • How to use a CTE in a CASE statement?

    Hi everyone,
    I'm trying to use a CTE in a CASE statement and getting error. In fact, I'm not sure how to use a CTE in this case and this is the first time I'm using a CTE. I managed to build a CTE successfully but, failed to incorporate it in the CASE statement.
    SELECT wbs,
    MIN(srt),
    MAX(srt)
    CASE ust
    WHEN
    WITH CTE AS
    SELECT p_id + p_name + ps_name AS colg, p_id
    FROM pd_info
    WHERE s_desc = 'warehouse'
    OR p_desc = 'Originated from warehouse'
    OR p_desc = 'Originated from a partner store'
    SELECT colg FROM CTE
    WHERE cte.colg IN (SELECT p_id + p_name + ps_name AS c
    omb from pd_info)
    OR cte.p_id = 'xxxxxxxx' THEN 'invalid'
    ELSE 'valid'
    END,
    p_name,
    sub_name,
    ps_name,
    FROM pd_info;
    Could experts here please help me?
    Thank you,
    Bangaaram
    Known is a DROP, Unknown is an OCEAN.

    With the help from some experts, I've figured out that CTE doesn't work in this case. Here are the queries that I'm using for the above. Either of them is working good so far.
    SELECT Wbs
    , MIN ( Srt )
    , MAX ( Srt )
    , CASE
    WHEN S_Desc = 'warehouse'
    OR P_Desc = 'Originated from warehouse'
    OR P_Desc = 'Originated from a partner store'
    OR P_Id = 'xxxxxxxx'
    THEN 'invalid'
    ELSE 'valid'
    END AS Ust
    , P_Name
    , Sub_Name
    , Ps_Name
    FROM Pd_Info
    GROUP BY Wbs
    , CASE
    WHEN S_Desc = 'warehouse'
    OR P_Desc = 'Originated from warehouse'
    OR P_Desc = 'Originated from a partner store'
    OR P_Id = 'xxxxxxxx'
    THEN 'invalid'
    ELSE 'valid'
    END
    , P_Name
    , Sub_Name
    , Ps_Name;
    SELECT wbs,
    MIN(srt),
    MAX(srt)
    CASE
    WHEN cte.p_id = 'xxxxxxxx'
    or exists
    (select *
    from pd_info p2
    WHERE (s_desc = 'warehouse'
    OR p_desc = 'Originated from warehouse'
    OR p_desc = 'Originated from a partner store' )
    and p2.p_id = p1.p_id and p2.p_name = p1.p_name and p2.ps_name = p1.ps_name
    THEN 'invalid'
    ELSE 'valid'
    END ust,
    p_name,
    sub_name,
    ps_name,
    FROM pd_info p1;
    Thank you,
    Bangaaram
    Known is a DROP, Unknown is an OCEAN.

  • Partition by range using greater than or in between statment?

    Can you partition by range using greater than or in between statment? If so, can someone please post the syntax?

    ji**** wrote:
    Can you partition by range using greater than or in between statment? If so, can someone please post the syntax?http://download.oracle.com/docs/cd/B10500_01/server.920/a96524/c12parti.htm
    CREATE TABLE sales_range
    (salesman_id  NUMBER(5),
    salesman_name VARCHAR2(30),
    sales_amount  NUMBER(10),
    sales_date    DATE)
    PARTITION BY RANGE(sales_date)
    PARTITION sales_jan2000 VALUES LESS THAN(TO_DATE('02/01/2000','DD/MM/YYYY')),
    PARTITION sales_feb2000 VALUES LESS THAN(TO_DATE('03/01/2000','DD/MM/YYYY')),
    PARTITION sales_mar2000 VALUES LESS THAN(TO_DATE('04/01/2000','DD/MM/YYYY')),
    PARTITION sales_apr2000 VALUES LESS THAN(TO_DATE('05/01/2000','DD/MM/YYYY'))
    );

  • How to use (greater than) in web services call

    Hello, I am trying to query a set of assets where the external unique ID is greater than 400,000. My existing code looks like
    qryIn.ListOfAsset(0).ExternalSystemId = ">'400000'"
    However, using this will return any asset record starting with a 5 or above as far as I can tell, I assume b/c it is comparing string data due to the single quotes infering data of type text (string). Is it possible to use comparison operators with numeric data correctly?
    I posed this question to support and received the below answer:
    <?xml version="1.0" encoding="UTF-8" standalone="no"?> <soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema"> <soap:Body> <AssetWS_AssetQueryPage_Input xmlns="urn:crmondemand/ws/asset/"> <ListOfAsset xmlns="urn:/crmondemand/xml/asset"> <Asset> <AssetId /> <PurchaseDate/> <OwnerAccountId /> <ExternalSystemId>&gt; '400000'</ExternalSystemId> </Asset> </ListOfAsset> </AssetWS_AssetQueryPage_Input> </soap:Body> </soap:Envelope>
    Basically, instructing me to use &gt. I'm doing coding in .NET visual studio and not using the XML as above. However, I did try the following:
    qryIn.ListOfAsset(0).ExternalSystemId = "&gt;'400000'" which returned an error in the compiler.
    Any help would be appreciated. Thanks.

    Thanks for the reply. I would assume "external system id" is an integer, but, I will test on a custom field that I now is of type integer.
    Could you take your same code and use a non-zero value for the operand? For example, could you try
    objAccQryParam.ListOfAccount[0].CustomInteger0 = ">= '10'"; and let me know if that returns values that are greater than or equal to 10. Using a two digit number is important. Assuming you have data greater than 10.
    Thanks!

  • Xpath query using greater than operator

    I'm trying to evaluate some xml to determine if it matches some criterium.
    MyXmlColumns contains the following kind of data "<Values><Value>data1</Value><Value>data2</Value><Values>"
    When I execute the following query I get zero rows returned when it should match some rows containing this data.
    select * from mydata
    where existsNode(MyXmlColumn, '/Values/Value[. > "data1"]') = 1
    The question is why greter than, lesser than, does not work, and if there is any alternative.
    If I use equals operator, or greater than but using a number it works.
    I know that I can use XmlExists function but I'm using Oracle 9i r2 so it's not an option.
    Thanks in advance for any suggestion.

    but I'm using Oracle 9i r2
    The question is why greter than, lesser than, does not workWorks on 9.2.0.8:
    SQL> select * from v$version where rownum = 1
    BANNER                                                         
    Oracle9i Enterprise Edition Release 9.2.0.8.0 - 64bit Production
    1 row selected.
    SQL> with mydata as
       select xmltype('<Values><Value>data1</Value><Value>data2</Value></Values>') MyXmlColumn from dual
    select * from mydata t where existsNode(t.MyXmlColumn, '/Values/Value') < 3
    MYXMLCOLUMN                                                              
    <Values>                                                                 
      <Value>data1</Value>                                                   
      <Value>data2</Value>                                                   
    </Values>                                                                
    1 row selected.

  • Problem with Filtering Data by Using "Greater Than" in APD

    Dear Experts,
      First of all, I am a novice of SAP Data Mining. I try to filter data in APD by using the 'Restrict Amont of Data (the Filter Icon).' My problem is really simple. I don't know how to filter data which have value greater than a constant.
    For example, I try to keep only records which have a quantity greater than 1000.
      At the selection option in the single value tab, I found only the '=' option. The options like '>', '<', '>=', etc are not found. Could anyone suggest me please?

    I do appreciate your prompt response.
    Seemingly, using the interval is our best solution, though it is not best for our customers.
    Having already gone through the note you gave me, in fact, it is really pertinent. Unfortunately, our support package is now 13, and it is extremely difficult to retest our system if we decide to apply the support package 16.
    Are there any other solution?
    By the way, you deserve my point.

  • KQL query using "Greater Than" fails

    I have developed a CSOM app that does a KQL query against several managed properties. One of these properties is numeric (mapped to RefinableDouble01), so I have a greater than (>) comparison in the query string:
         RefinableDouble01>41.12345
    I developed the app in Office 365 and when I run the query there, it works fine (no errors).  However, when I run it to our internal SharePoint 2013 site, it fails with the error:
         "We didn't understand your search terms. Make sure they're using proper syntax."
    As far as I can tell, the configuration of the internal site matches the Office 365 site.
    If I use a query on a text property, so that I don't use the greater than comparison, that query works. The query results from that query also show that the managed property RefinableDouble01 is properly mapped and returns the expected numeric value.
    Does anyone know what the problem is? I'm wondering if the KQL query functionality is not properly set up in our internal site, but that is not an area that I am familiar with.
    Bob Feldman

    Here is more information, from the ULS Log file, regarding the error:
    06/27/2014 11:05:13.47  NodeRunnerQuery1-d8a6a564-7b37- (0x0BA4) 0x0DC4 Search                         Query Processing             
     aizc0 High     Microsoft.Office.Server.Search.Query.Ims.ImsQueryInternal : New request: Query text 'RefinableDouble01>41.12345', Query template ''; HiddenConstraints: ; SiteSubscriptionId: 00000000-0000-0000-0000-000000000000 fa039f9c-0884-60df-c11a-64f9b09837c4
    06/27/2014 11:05:13.48  NodeRunnerQuery1-d8a6a564-7b37- (0x0BA4) 0x0DC4 Search                         Query Processing             
     aizgn Medium   Microsoft.Office.Server.Search.Query.Pipeline.Executors.QueryPipelineHardWiredFlowExecutor : (FlowExecutor)eventSearchFlowDone: d8a6a564-7b37-4815-a35f-f97acc0d6cba, RefinableDouble01>41.12345, Microsoft.ProductivitySearchFlow,
    0, SPWFEAPP, Error=Exception occurred due to some other exception fa039f9c-0884-60df-c11a-64f9b09837c4 fa039f9c-0884-60df-c11a-64f9b09837c4
    06/27/2014 11:05:13.48  NodeRunner.exe (0x0BA4)                  0x0DC4 SharePoint Server Search       Query                        
     aisyt High     ExecuteFlowInternal FlowExecutor:Microsoft.ProductivitySearchFlow Exception: Microsoft.Ceres.Evaluation.DataModel.CommonEvaluationException: Exception occurred due to some other exception ---> Microsoft.Office.Server.Search.Query.QueryMalformedException:
    Query 'RefinableDouble01>41.12345' failed: syntax error at position 0, The operation is illegal for the given property, property expression: RefinableDouble01>41.8882213637562     --- End of inner exception stack trace ---    
    at Microsoft.Office.Server.Search.Query.Pipeline.Processing.KeywordQueryParserEvaluator.KeywordQueryParserProducer.ParseKeywordQuery(String queryText, ParsingContext parsingContext, Boolean debugMode, String& searchTerms)     at Microsoft.Office.Server.Search.Query.Pipeline.Processing.KeywordQueryParserEvalua... fa039f9c-0884-60df-c11a-64f9b09837c4
    06/27/2014 11:05:13.48  w3wp.exe (0x196C)                        0x41B0 SharePoint Server Search       Query                        
     dk68 High     SearchServiceApplication::Execute--Exception: Microsoft.Office.Server.Search.Query.QueryMalformedException: We didn't understand your search terms. Make sure they're using proper syntax. ---> System.ServiceModel.FaultException`1[Microsoft.Office.Server.Search.Administration.SearchServiceApplicationFault]:
    Query 'RefinableDouble01>41.12345' failed: syntax error at position 0, The operation is illegal for the given property, property expression: RefinableDouble01>41.8882213637562    Server stack trace:      at System.ServiceModel.Channels.ServiceChannel.HandleReply(ProxyOperationRuntime
    operation, ProxyRpc& rpc)     at System.ServiceModel.Channels.ServiceChannel.Call(String action, Boolean oneway, ProxyOperationRuntime operation, Object[] ins, Object[] outs, TimeSpan timeout)     at ... fa039f9c-0884-60df-c11a-64f9b09837c4

  • Using 'Greater than/less than' in dynamic where condition

    Hi Guys,
    I am trying to use a logical expression with GT/LT condition in dynamic where, butits giving dump  "expression worngly parenthesised' . My query runs perfectly fine when the logical expression does not have 'GT/LT' . Is there a different way of using GT/LT in dynamic where or is it not posiible at all?? Please find my query below -
    IF vendor IS NOT INITIAL.
          i_where_clause = 'a~lifnr = vendor'.
          APPEND i_where_clause.
          CLEAR i_where_clause.
        ENDIF.
        IF to_date IS NOT INITIAL.
          i_where_clause = 'a~zzearliestdep LT to_date'.
          APPEND i_where_clause.
          CLEAR i_where_clause.
        ENDIF.
        IF from_date IS NOT INITIAL.
          i_where_clause = 'a~zzlatestdep GT from_date'.
          APPEND i_where_clause.
          CLEAR i_where_clause.
        ENDIF.
      SELECT aebeln alifnr azzearliestdep azzlatestdep
                bebelp belikz b~kzabs
           INTO CORRESPONDING FIELDS OF TABLE i_podetails
           UP TO max_hits ROWS
           FROM ( ekko AS a INNER JOIN ekpo AS b
                   ON aebeln = bebeln )
           WHERE a~ebeln = ebeln AND
                (i_where_clause).

    Hi,
    Try this -
    IF vendor IS NOT INITIAL.
      i_where_clause = 'a~lifnr = vendor'.
      APPEND i_where_clause.
    ENDIF.
    IF to_date IS NOT INITIAL.
      if i_where_cause[] is not initial.
        i_where_clause = 'AND'
        append i_where_cause.
      endif.
      i_where_clause = 'a~zzearliestdep LT to_date'.
      APPEND i_where_clause.
    ENDIF.
    IF from_date IS NOT INITIAL.
      if i_where_cause[] is not initial.
        i_where_clause = 'AND'
        append i_where_cause.
      endif.
      i_where_clause = 'a~zzlatestdep GT from_date'.
      APPEND i_where_clause.
      CLEAR i_where_clause.
    ENDIF.
    Cheers.
    \[removed by moderator\]
    Edited by: Jan Stallkamp on Jun 26, 2008 1:08 PM

  • Greater than sign in switch statement

    it wont allow me to use the greater than sign in this program how can i fix this?
    public class q2b
        public static void main (String [] args)
            int x = 2;
            switch (x)
            case 'x < 1'
            System.out.println("x is less than 1");
            break;
    }

    what do u mean by posting the print statements,
    this is the new code
    public class q2b
        public static void main (String [] args)
            int x = 2;
            switch (x)
            case '1':
            System.out.println("x is 1");
            break;
            case '2':
            System.out.println("x is2");
            break;
            case '3':
            System.out.println("x is 3");
            break;
            case '4':
            System.out.println("x is 4");
            break;
            default:
            System.out.println("x is greater than 4 or x is less than 1");
            break;
    }i should be seeing "x is2" but instead it is showing up as "x is greater than 4 or x is less than 1"
    please help

  • Using greater than - less than in a date query in a form

    In version 5, the user could put in ">03/05/08" in a date field, hit the execute query button, and the form would pull up everything >3/5/2008. In version 10g, I get all format errors when I put in the same thing. Is there a work-around, or is this feature no longer supported in 10g?

    I assume you have recently performed an upgrade to Forms 10g. Did you only upgrade to Forms 10g or were their other upgrades as well (like the Database)? Has the NLS_DATE_FORMAT changed? Can you run your query in SQL*Plus successfully? Any additional information you can provide will greatly aid us in helping you troubleshoot this issue.
    Craig...

  • Updates using greater than or less than logic....

    Hi, I've run into something that I can't figure out how to do through the OWB GUI. I have a source table that tells me that data changed between a given effective start and effective end dates (for example, NAME information). Given that, I want to update all rows in the person dimension tied to the matching person, where the effective date on the person dim is between the effective start and end dates on the source table.
    Using the standard update operator, it looks like the only option I have is "=", I can't specify "<=" or ">=".
    Is there any (easy) way around this?
    Thanks,
    Scott

    I'd like to expand on Bharad's join condition.
    Keep in mind that you have to use the effective start date two times (see below).
    ingrp1 a.person_id =ingrp2 b.person_id
    and ingrp1 a.effective_start_date >= ingrp2 b.effective_start_date
    and ingrp1 a.effective_startdate <= ingrp2 b.effectiveend_date
    Also, in most dimension tables the effective end date can contain NULL values which we need to take care off as well otherwise we will 'lose' records. A NVL can fix that problem, for example:
    ingrp1 a.person_id =ingrp2 b.person_id
    and ingrp1 a.effective_start_date >= ingrp2 b.effective_start_date
    and ingrp1 a.effective_start_date <= nvl( ingrp2 b.effective_end_date, sysdate)
    You can also substitute sysdate for a fixed date in the future but it's not dynamic then.

  • Disk Utility shows Used greater than Capacity?

    I have a Smartdisk 80GB Firelite that is partitioned and erased, yet in disk utility it shows 74.4GB Capacity, 74.4GB Available, and 34.6GB Used. That doesn't make any sense at all. How can I get the used space back to Zero?

    Yes, I've used Disk Utility to partition. I've done 1 partition, 2 partitions, 16 partitions, I've partitioned as Unix then back to Mac OS. When I had 16 partitions there were about 4.5 GBs per partition and it would say 20.4 GBs used on a 4.5 GB partition, this is the readout at the bottom of Disk Utility when you click on the drive. I've ran repair disk and everything is okay. I've ran Disk Warrior and everything is okay. It's very strange, my 80gb Firelite drive is completely empty, no data, it's been erased and partitioned a number of times and Disk Utility still says it has Used GBs, when it should be close to zero.

  • Can we use alias name in the case statement?

    select sal,
    case sal
    when 500 then 'low'
    when 5000 then 'high'
    else 'medium'
    end case
    from emp;
    OUTPUT
    sal    case
    4587 medium
    5000 high
    .....so  can i have range in the place of  case  at output?

    select nvl(sal,0) sal, case when nvl(sal,0)<=500 then 'low' when nvl(sal,0)>=5000 then 'high' else 'medium' end range from emp;
    Output
    SAL RANGE
    450 low
    5000 high
    300 low
    4000 medium
    3700 medium
    4750 medium
    2000 medium

  • Regular Expression Search for Case Statement in VBA

    Hi,
    I'm having trouble trying to use regular expressions in a case statement. I have a CSV spreadsheet of a server's netstat output and am trying to plot everything into Visio. I have been able to do that, however I'm not trying to expand this capability and
    resuse the same code for many different servers. 
    I have the mainServer variable set as a Variant and in my current example it is set as "INTPXY001" (internal proxy server 001). I have tried different regex statements for the potential to have INTPXY001 - INTPXY999, EXTPXY001 - EXTPXY999, and
    SVCPXY001 - SVCPXY999 in place of the Case "INTPXY001", but nothing I have tried seems to work.
    '========================================
    Set mainServer As Variant
    Set AppVisio = CreateObject("visio.application")
    AppVisio.Visible = True
    AppVisio.Documents.AddEx "", visMSDefault, 0
    AppVisio.Documents.OpenEx "server_u.vss", visOpenRO + visOpenDocked
    mainServer = ActiveSheet.Cells(1, 2) 'sets mainServer to INTPXY001
    With AppVisio.ActiveWindow.Page
    Select Case mainServer
    Case "INTPXY001"
    .Drop AppVisio.Documents.Item("SERVER_U.VSS").Masters.ItemU("Proxy server"), 2.25, 9.25
    Case Else
    .Drop AppVisio.Documents.Item("SERVER_U.VSS").Masters.Item(("Server"), 2.25, 9.25
    End Select
    End With
    '========================================

    You cannot declare variables As Variant in VBScript. All variables in VBScript are implicitly variants.
    If you are asking about VBA (Visual Basic for Applications), then you're not asking in the correct forum.
    -- Bill Stewart [Bill_Stewart]

  • Subquery inside CASE statement

    I am trying to use a subquery within a Case statement with a 'where' condition that binds to the parent query. Like this:
    Select T.idperson , CASE WHEN  T.type = 'C' THEN (SELECT name from Customers where C.idcustomer = T.idperson)
    ELSE
    (SELECT name from Providers where idprovider = T.idperson)
    END Name
    from myTable T This works for me in SQL Server but in ORACLE the subquery does not return any rows, i guess its the binding to parent query part. Any thoughts of another way I could get the result I want?
    Thanks,
    JuanDiego

    Hi, Juandiego,
    If it's not returning any rows, then you must not have any rows in the table.
    If you have any rows in the table, you will either get
    (a) an error, or
    (b) some rows (even if the columns are NULL).
    There is another way to get the results you want.
    I probably wouldn't use scalar sub-queries. I would outer-join all the tables, like this:
    Select  T.idperson
    ,       CASE
                WHEN  T.type = 'C'
                THEN  c.name
                ELSE  p.name
            END  AS Name
    from             myTable   t
    LEFT OUTER JOIN  Customers c  ON c.idcustomer = T.idperson
    LEFT OUTER JOIN  Providers p  ON p.idprovider = T.idperson
    ;

Maybe you are looking for

  • Error while accessing transaction codes through URL's in IFrame UI element

    Hi Experts, I have created Transaction iviews ck91N, ck11N, ck24 in SAP NW CE7.2. I am accessing these Transaction iviews through URL's in webdynpro java application. I am using IFrame UI element in a Roadmap UI for each transaction code. when i acce

  • Error when creating transfer structure in source system

    We have just had a copy of the ERP production system done and connected it to our existing QA system (done by our service providers) for a test go-live of our ERP upgrade. Now I cannot activate the transfer rules as the transfer structure cannot be c

  • [ISA570][router212c52]IPS Alert

    Hi all. Last night I set up my new Playstation 4 and after some messing around my ISA570 sent me this email. (see attached Text file) The destination address is my PS4. and I did recall having some trouble with some of the services. Question is this.

  • CREATING XML TAG W/SPACES and CDATA.  EXPORTED FROM PDF BUTTON

    Hello All, I was wondering if anyone could help with the following when working with livecycle Designer. In our current XML we use in production we have a tag that looks like a.       <action function='Form1650' method='Add' and Action 'Upload' /> Ho

  • Form on web

    Is there a way to find out if a form is runnig in Client/Server mode or is running in the Web-browser?