Tableau case when statement in SQL

IF statement in the SQL string

For developers: SQL Server https://social.msdn.microsoft.com/Forums/de-DE/a76a9250-0374-419e-ab5a-c0f94a5b74ad/ifanweisung-im-sqlstringQuestion308.06.2012 09: 14: 0013.05.2014 11:24: 45This forum serves as a discussion platform for software development issues relating to the SQL Server. For example, you can discuss database programming or SQL Server database queries and exchange information, tips and tricks. In this forum, beginners as well as professionals can exchange ideas in order to jointly solve problems relating to SQL Server
  • question

  • text / html 06/08/2012 09:14:00 Michael Pleick0

    Hello,

    I want to (have to) intercept the result of a 0 in an SQL statement with an IF statement. Now I can't find any syntax for it. Is that possible?

    greeting

    Michael

reply

  • text / sourcefragment 06/08/2012 09: 17: 43Olaf Helper1

    Hi Michael,

    can you describe in more detail what you intend to do?

    There is an IF command, but it is only intended for process control. In an SQL statement itself, you can work with the CASE WHEN statement, e.g.

    SELECT CASE WHEN MyField = 0 THEN 'Is zero' ELSE 'Not 0' END AS Result FROM myTable;

    Olaf Helper
    * cogito ergo sum * errare humanum est * quote erat demonstrandum *
    If I think it's a mistake and I prove it every day
    Blog Xing

All answers

  • text / sourcefragment 06/08/2012 09: 17: 43Olaf Helper1

    Hi Michael,

    can you describe in more detail what you intend to do?

    There is an IF command, but it is only intended for sequence control. In an SQL statement itself, you can work with the CASE WHEN statement, e.g.

    SELECT CASE WHEN MyField = 0 THEN 'Is zero' ELSE 'Not 0' END AS Result FROM myTable;

    Olaf Helper
    * cogito ergo sum * errare humanum est * quote erat demonstrandum *
    If I think it's a mistake and I prove it every day
    Blog Xing

  • text / html 06/08/2012 10:20:25 AM Michael Pleick0

    Hello Olaf,

    worked. I was looking for exactly this Syntea.

    thanks

    Michael