D
D
des1roer2015-09-04 13:42:19
PostgreSQL
des1roer, 2015-09-04 13:42:19

How to use if in postgres?

SELECT "F_TagName_ID",
          "F_Date",
          "F_ConvertedValue",
          IF (8 < to_char("F_Date", 'H24')::int
   AND to_char("F_Date", 'H24')::int < 20) THEN RETURN  2 AS smena ; ELSE  RETURN  1 AS smena;
   END IF;
   FROM "SC_Tag"."T_TagData"

how to use if-else

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Andrey Burov, 2015-09-04
@BuriK666

Use CASE
Something like this:

SELECT "F_TagName_ID",
          "F_Date",
          "F_ConvertedValue",
          CASE WHEN (8 < to_char("F_Date", 'H24')::int
   AND to_char("F_Date", 'H24')::int < 20) THEN  2  ELSE 1 END AS smena
   FROM "SC_Tag"."T_TagData"

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question