<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>Question Re: IF statement in SELECT statement in Technology Q&amp;A</title>
    <link>https://community.sap.com/t5/technology-q-a/if-statement-in-select-statement/qaa-p/13835933#M4866776</link>
    <description>&lt;P&gt;try this if answer 2 doesn't work&lt;BR /&gt;
IF (SELECT rest_name FROM dbo.rest_def)='Safari' THEN 'AWS' ELSE 'SCT' END IF&lt;BR /&gt;
BTW your original SQL also has a comma after the end if&lt;/P&gt;</description>
    <pubDate>Sat, 15 Mar 2014 17:43:38 GMT</pubDate>
    <dc:creator>t1950</dc:creator>
    <dc:date>2014-03-15T17:43:38Z</dc:date>
    <item>
      <title>IF statement in SELECT statement</title>
      <link>https://community.sap.com/t5/technology-q-a/if-statement-in-select-statement/qaq-p/13835931</link>
      <description>&lt;P&gt;Hi Guys,&lt;/P&gt;
&lt;P&gt;I need some help here. I'm trying to put a logical statement into my output statement but apparently it doesn't work. Script as below:&lt;/P&gt;
&lt;DIV class="codehilite"&gt;&lt;PRE&gt;&lt;SPAN class="n"&gt;UNLOAD&lt;/SPAN&gt;
    &lt;SPAN class="n"&gt;SELECT&lt;/SPAN&gt; 
        &lt;SPAN class="n"&gt;REPLACE&lt;/SPAN&gt;&lt;SPAN class="p"&gt;((&lt;/SPAN&gt;&lt;SPAN class="n"&gt;SUBSTRING&lt;/SPAN&gt;&lt;SPAN class="p"&gt;(&lt;/SPAN&gt;&lt;SPAN class="n"&gt;dbo&lt;/SPAN&gt;&lt;SPAN class="o"&gt;.&lt;/SPAN&gt;&lt;SPAN class="n"&gt;dly_srv_prd_trk_ttl&lt;/SPAN&gt;&lt;SPAN class="o"&gt;.&lt;/SPAN&gt;&lt;SPAN class="n"&gt;business_date&lt;/SPAN&gt;&lt;SPAN class="p"&gt;,&lt;/SPAN&gt;&lt;SPAN class="mi"&gt;1&lt;/SPAN&gt;&lt;SPAN class="p"&gt;,&lt;/SPAN&gt;&lt;SPAN class="mi"&gt;7&lt;/SPAN&gt;&lt;SPAN class="p"&gt;)),&lt;/SPAN&gt;&lt;SPAN class="s"&gt;'-'&lt;/SPAN&gt;&lt;SPAN class="p"&gt;,&lt;/SPAN&gt;&lt;SPAN class="s"&gt;'0'&lt;/SPAN&gt;&lt;SPAN class="p"&gt;),&lt;/SPAN&gt;
        &lt;SPAN class="n"&gt;DATEFORMAT&lt;/SPAN&gt;&lt;SPAN class="p"&gt;(&lt;/SPAN&gt;&lt;SPAN class="n"&gt;dbo&lt;/SPAN&gt;&lt;SPAN class="o"&gt;.&lt;/SPAN&gt;&lt;SPAN class="n"&gt;dly_srv_prd_trk_ttl&lt;/SPAN&gt;&lt;SPAN class="o"&gt;.&lt;/SPAN&gt;&lt;SPAN class="n"&gt;business_date&lt;/SPAN&gt;&lt;SPAN class="p"&gt;,&lt;/SPAN&gt;&lt;SPAN class="s"&gt;'dd/mm/yyyy'&lt;/SPAN&gt;&lt;SPAN class="p"&gt;),&lt;/SPAN&gt;
        &lt;SPAN class="n"&gt;dbo&lt;/SPAN&gt;&lt;SPAN class="o"&gt;.&lt;/SPAN&gt;&lt;SPAN class="n"&gt;dly_srv_prd_trk_ttl&lt;/SPAN&gt;&lt;SPAN class="o"&gt;.&lt;/SPAN&gt;&lt;SPAN class="n"&gt;trk_ttl_01&lt;/SPAN&gt;&lt;SPAN class="p"&gt;,&lt;/SPAN&gt;
        &lt;SPAN class="n"&gt;DATEFORMAT&lt;/SPAN&gt;&lt;SPAN class="p"&gt;(&lt;/SPAN&gt;&lt;SPAN class="n"&gt;dbo&lt;/SPAN&gt;&lt;SPAN class="o"&gt;.&lt;/SPAN&gt;&lt;SPAN class="n"&gt;dly_srv_prd_trk_ttl&lt;/SPAN&gt;&lt;SPAN class="o"&gt;.&lt;/SPAN&gt;&lt;SPAN class="n"&gt;business_date&lt;/SPAN&gt;&lt;SPAN class="p"&gt;,&lt;/SPAN&gt;&lt;SPAN class="s"&gt;'dd'&lt;/SPAN&gt;&lt;SPAN class="p"&gt;),&lt;/SPAN&gt;
        &lt;SPAN class="n"&gt;dbo&lt;/SPAN&gt;&lt;SPAN class="o"&gt;.&lt;/SPAN&gt;&lt;SPAN class="n"&gt;dly_srv_prd_trk_ttl&lt;/SPAN&gt;&lt;SPAN class="o"&gt;.&lt;/SPAN&gt;&lt;SPAN class="n"&gt;rvc_seq&lt;/SPAN&gt;&lt;SPAN class="p"&gt;,&lt;/SPAN&gt;
        &lt;SPAN class="n"&gt;IF&lt;/SPAN&gt; &lt;SPAN class="p"&gt;(&lt;/SPAN&gt;&lt;SPAN class="n"&gt;SELECT&lt;/SPAN&gt; &lt;SPAN class="n"&gt;rest_name&lt;/SPAN&gt; &lt;SPAN class="n"&gt;FROM&lt;/SPAN&gt; &lt;SPAN class="n"&gt;dbo&lt;/SPAN&gt;&lt;SPAN class="o"&gt;.&lt;/SPAN&gt;&lt;SPAN class="n"&gt;rest_def&lt;/SPAN&gt;&lt;SPAN class="p"&gt;)&lt;/SPAN&gt;&lt;SPAN class="o"&gt;=&lt;/SPAN&gt;&lt;SPAN class="s"&gt;'Safari'&lt;/SPAN&gt; &lt;SPAN class="n"&gt;THEN&lt;/SPAN&gt; &lt;SPAN class="n"&gt;SELECT&lt;/SPAN&gt; &lt;SPAN class="n"&gt;STRING&lt;/SPAN&gt;&lt;SPAN class="p"&gt;(&lt;/SPAN&gt;&lt;SPAN class="s"&gt;'AWS'&lt;/SPAN&gt;&lt;SPAN class="p"&gt;)&lt;/SPAN&gt; &lt;SPAN class="n"&gt;ELSE&lt;/SPAN&gt;    &lt;SPAN class="n"&gt;SELECT&lt;/SPAN&gt; &lt;SPAN class="n"&gt;STRING&lt;/SPAN&gt;&lt;SPAN class="p"&gt;(&lt;/SPAN&gt;&lt;SPAN class="s"&gt;'SCT'&lt;/SPAN&gt;&lt;SPAN class="p"&gt;)&lt;/SPAN&gt; &lt;SPAN class="k"&gt;END&lt;/SPAN&gt; &lt;SPAN class="n"&gt;IF&lt;/SPAN&gt;&lt;SPAN class="p"&gt;,&lt;/SPAN&gt;
    &lt;SPAN class="n"&gt;FROM&lt;/SPAN&gt; &lt;SPAN class="n"&gt;dbo&lt;/SPAN&gt;&lt;SPAN class="o"&gt;.&lt;/SPAN&gt;&lt;SPAN class="n"&gt;dly_srv_prd_trk_ttl&lt;/SPAN&gt;

&lt;SPAN class="n"&gt;TO&lt;/SPAN&gt; &lt;SPAN class="s"&gt;'D:\\SUN\\DATA.txt'&lt;/SPAN&gt; &lt;SPAN class="n"&gt;FORMAT&lt;/SPAN&gt; &lt;SPAN class="n"&gt;FIXED&lt;/SPAN&gt;
&lt;/PRE&gt;&lt;/DIV&gt;


&lt;P&gt;I have tested each of the statement inside and they are working when running alone. Error prompts "Syntax error near 'SELECT' on line 7".&lt;/P&gt;
&lt;P&gt;Please help &lt;span class="lia-unicode-emoji" title=":disappointed_face:"&gt;😞&lt;/span&gt;&lt;/P&gt;</description>
      <pubDate>Fri, 14 Mar 2014 05:19:35 GMT</pubDate>
      <guid>https://community.sap.com/t5/technology-q-a/if-statement-in-select-statement/qaq-p/13835931</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2014-03-14T05:19:35Z</dc:date>
    </item>
    <item>
      <title>Re: IF statement in SELECT statement</title>
      <link>https://community.sap.com/t5/technology-q-a/if-statement-in-select-statement/qaa-p/13835932#M4866775</link>
      <description>&lt;P&gt;well try this &lt;/P&gt;
&lt;P&gt;IF 'Safari' IN (SELECT rest_name FROM dbo.rest_def)THEN ('AWS') ELSE ('SCT') END IF&lt;/P&gt;</description>
      <pubDate>Fri, 14 Mar 2014 05:36:31 GMT</pubDate>
      <guid>https://community.sap.com/t5/technology-q-a/if-statement-in-select-statement/qaa-p/13835932#M4866775</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2014-03-14T05:36:31Z</dc:date>
    </item>
    <item>
      <title>Re: IF statement in SELECT statement</title>
      <link>https://community.sap.com/t5/technology-q-a/if-statement-in-select-statement/qaa-p/13835934#M4866777</link>
      <description>&lt;P&gt;In addition to what M G said, the IF you have coded is an "IF expression" rather than an "IF statement". They look very similar BUT an IF expression returns a single value, whereas an IF statement chooses between blocks of code (other statements) to execute. A SELECT list consists of a list of expressions, and you can code expressions inside expressions, but you cannot code a statement inside an expression. For the record, there is also a CASE expression as well as a CASE statement, both are very valuable.&lt;/P&gt;</description>
      <pubDate>Fri, 14 Mar 2014 08:25:59 GMT</pubDate>
      <guid>https://community.sap.com/t5/technology-q-a/if-statement-in-select-statement/qaa-p/13835934#M4866777</guid>
      <dc:creator>Breck_Carter</dc:creator>
      <dc:date>2014-03-14T08:25:59Z</dc:date>
    </item>
    <item>
      <title>Re: IF statement in SELECT statement</title>
      <link>https://community.sap.com/t5/technology-q-a/if-statement-in-select-statement/qaa-p/13835933#M4866776</link>
      <description>&lt;P&gt;try this if answer 2 doesn't work&lt;BR /&gt;
IF (SELECT rest_name FROM dbo.rest_def)='Safari' THEN 'AWS' ELSE 'SCT' END IF&lt;BR /&gt;
BTW your original SQL also has a comma after the end if&lt;/P&gt;</description>
      <pubDate>Sat, 15 Mar 2014 17:43:38 GMT</pubDate>
      <guid>https://community.sap.com/t5/technology-q-a/if-statement-in-select-statement/qaa-p/13835933#M4866776</guid>
      <dc:creator>t1950</dc:creator>
      <dc:date>2014-03-15T17:43:38Z</dc:date>
    </item>
    <item>
      <title>Re: IF statement in SELECT statement</title>
      <link>https://community.sap.com/t5/technology-q-a/if-statement-in-select-statement/qaa-p/13835935#M4866778</link>
      <description>&lt;P&gt;Hi M G and Tom, very appreciate your effort. However they did not work and comes out with syntax error on 'END'.&lt;/P&gt;
&lt;P&gt;I've tried to search in detail in other where and found out this: &lt;A href="http://forums.devshed.com/ms-sql-development-95/statement-select-help-135322.html"&gt;http://forums.devshed.com/ms-sql-development-95/statement-select-help-135322.html&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;Therefore I change the expression a little bit as below and it works!&lt;/P&gt;
&lt;DIV class="codehilite"&gt;&lt;PRE&gt;&lt;SPAN class="n"&gt;CASE&lt;/SPAN&gt; &lt;SPAN class="n"&gt;WHEN&lt;/SPAN&gt; &lt;SPAN class="p"&gt;(&lt;/SPAN&gt;&lt;SPAN class="n"&gt;SELECT&lt;/SPAN&gt; &lt;SPAN class="n"&gt;rest_name&lt;/SPAN&gt; &lt;SPAN class="n"&gt;FROM&lt;/SPAN&gt; &lt;SPAN class="n"&gt;dbo&lt;/SPAN&gt;&lt;SPAN class="o"&gt;.&lt;/SPAN&gt;&lt;SPAN class="n"&gt;rest_def&lt;/SPAN&gt;&lt;SPAN class="p"&gt;)&lt;/SPAN&gt;&lt;SPAN class="o"&gt;=&lt;/SPAN&gt;&lt;SPAN class="s"&gt;'SAFARI'&lt;/SPAN&gt; &lt;SPAN class="n"&gt;THEN&lt;/SPAN&gt; &lt;SPAN class="s"&gt;'AWS'&lt;/SPAN&gt; &lt;SPAN class="n"&gt;ELSE&lt;/SPAN&gt; &lt;SPAN class="s"&gt;'SCT'&lt;/SPAN&gt; &lt;SPAN class="k"&gt;END&lt;/SPAN&gt;
&lt;/PRE&gt;&lt;/DIV&gt;


&lt;P&gt;Thanks again guys. You guys are really helpful &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;/P&gt;</description>
      <pubDate>Tue, 18 Mar 2014 03:06:26 GMT</pubDate>
      <guid>https://community.sap.com/t5/technology-q-a/if-statement-in-select-statement/qaa-p/13835935#M4866778</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2014-03-18T03:06:26Z</dc:date>
    </item>
    <item>
      <title>Re: IF statement in SELECT statement</title>
      <link>https://community.sap.com/t5/technology-q-a/if-statement-in-select-statement/qaa-p/13835936#M4866779</link>
      <description>&lt;P&gt;What version of SQL Anywhere are you using? Note: Versions before v11 would require a final "ENDIF" instead of "END IF" - with v11 and above, you can use either one.&lt;/P&gt;
&lt;P&gt;Note that the docs you have cited is for MS SQL Server - which does not allow IF expressions at all, so you have to use CASE expresssions there...&lt;/P&gt;</description>
      <pubDate>Tue, 18 Mar 2014 12:31:22 GMT</pubDate>
      <guid>https://community.sap.com/t5/technology-q-a/if-statement-in-select-statement/qaa-p/13835936#M4866779</guid>
      <dc:creator>VolkerBarth</dc:creator>
      <dc:date>2014-03-18T12:31:22Z</dc:date>
    </item>
    <item>
      <title>Re: IF statement in SELECT statement</title>
      <link>https://community.sap.com/t5/technology-q-a/if-statement-in-select-statement/qaa-p/13835937#M4866780</link>
      <description>&lt;P&gt;Hi Volker,&lt;/P&gt;
&lt;P&gt;It's V.9.0. My bad. And yes, once I change it to "ENDIF", it's running fine.&lt;/P&gt;
&lt;P&gt;Thanks again for the clue.&lt;/P&gt;</description>
      <pubDate>Tue, 18 Mar 2014 22:07:31 GMT</pubDate>
      <guid>https://community.sap.com/t5/technology-q-a/if-statement-in-select-statement/qaa-p/13835937#M4866780</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2014-03-18T22:07:31Z</dc:date>
    </item>
    <item>
      <title>Re: IF statement in SELECT statement</title>
      <link>https://community.sap.com/t5/technology-q-a/if-statement-in-select-statement/qaa-p/13835938#M4866781</link>
      <description>&lt;P&gt;ENDIF for compatibility with any SA version.&lt;/P&gt;</description>
      <pubDate>Wed, 19 Mar 2014 05:44:40 GMT</pubDate>
      <guid>https://community.sap.com/t5/technology-q-a/if-statement-in-select-statement/qaa-p/13835938#M4866781</guid>
      <dc:creator>former_SQLA_member1694880</dc:creator>
      <dc:date>2014-03-19T05:44:40Z</dc:date>
    </item>
    <item>
      <title>Re: IF statement in SELECT statement</title>
      <link>https://community.sap.com/t5/technology-q-a/if-statement-in-select-statement/qaa-p/13835939#M4866782</link>
      <description>&lt;P&gt;Guys, I am trying to add ELSEIF expression into the IF expression like above but I get an error "Syntax error near 'ELSEIF'.&lt;/P&gt;
&lt;P&gt;I've read and refer to Sybooks Online and it seemed to be correct. I have totally out of idea which part is the culprit.&lt;/P&gt;
&lt;P&gt;Please help...&lt;/P&gt;</description>
      <pubDate>Wed, 09 Apr 2014 05:26:55 GMT</pubDate>
      <guid>https://community.sap.com/t5/technology-q-a/if-statement-in-select-statement/qaa-p/13835939#M4866782</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2014-04-09T05:26:55Z</dc:date>
    </item>
    <item>
      <title>Re: IF statement in SELECT statement</title>
      <link>https://community.sap.com/t5/technology-q-a/if-statement-in-select-statement/qaa-p/13835940#M4866783</link>
      <description>&lt;P&gt;The IF expression does not support an ELSEIF branch - however, you can nest several IF expressions, such as&lt;/P&gt;
&lt;PRE class="codehilite"&gt;&lt;CODE class="language-sql"&gt;begin
  declare n int;
  set n = null;
  select if n &amp;gt; 0 then 'positive' else
            if n &amp;lt; 0 then 'negative' else
               if n = 0 then 'zero' else 'null' endif
            endif
         endif;
end;


&lt;P&gt;Aside: Several tests on the same variable/column would usually be expressed with a CASE expression but I guess you'll get the direction...&lt;/P&gt;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 09 Apr 2014 05:39:42 GMT</pubDate>
      <guid>https://community.sap.com/t5/technology-q-a/if-statement-in-select-statement/qaa-p/13835940#M4866783</guid>
      <dc:creator>VolkerBarth</dc:creator>
      <dc:date>2014-04-09T05:39:42Z</dc:date>
    </item>
    <item>
      <title>Re: IF statement in SELECT statement</title>
      <link>https://community.sap.com/t5/technology-q-a/if-statement-in-select-statement/qaa-p/13835941#M4866784</link>
      <description>&lt;P&gt;Oh my god, you are a genius! Thank you for the clue. Really appreciate it &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;/P&gt;</description>
      <pubDate>Wed, 09 Apr 2014 05:54:55 GMT</pubDate>
      <guid>https://community.sap.com/t5/technology-q-a/if-statement-in-select-statement/qaa-p/13835941#M4866784</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2014-04-09T05:54:55Z</dc:date>
    </item>
    <item>
      <title>Re: IF statement in SELECT statement</title>
      <link>https://community.sap.com/t5/technology-q-a/if-statement-in-select-statement/qaa-p/13835942#M4866785</link>
      <description>&lt;P&gt;Hi Volker,&lt;/P&gt;
&lt;P&gt;Is it possible that I create a procedure and call the procedure in the UNLOAD statement and nested among the functions?&lt;/P&gt;
&lt;P&gt;I found that I'd need to write a couple of times for the long list of IF...ELSE...ENDIF in order to grab a value.&lt;/P&gt;
&lt;P&gt;When I was trying to created one, I've got error on syntax "BEGIN" which is just right at the second line beneath of CREATE PROCEDURE xxx.&lt;/P&gt;</description>
      <pubDate>Thu, 10 Apr 2014 05:16:53 GMT</pubDate>
      <guid>https://community.sap.com/t5/technology-q-a/if-statement-in-select-statement/qaa-p/13835942#M4866785</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2014-04-10T05:16:53Z</dc:date>
    </item>
    <item>
      <title>Re: IF statement in SELECT statement</title>
      <link>https://community.sap.com/t5/technology-q-a/if-statement-in-select-statement/qaa-p/13835943#M4866786</link>
      <description>&lt;P&gt;That should be better asked as a separate question, and with the code you try to run.&lt;/P&gt;
&lt;P&gt;FWIW: You can certainly call stored procs in the UNLOAD SELECT statement.&lt;/P&gt;</description>
      <pubDate>Thu, 10 Apr 2014 08:30:52 GMT</pubDate>
      <guid>https://community.sap.com/t5/technology-q-a/if-statement-in-select-statement/qaa-p/13835943#M4866786</guid>
      <dc:creator>VolkerBarth</dc:creator>
      <dc:date>2014-04-10T08:30:52Z</dc:date>
    </item>
  </channel>
</rss>

