Search notes:

SQL Server: mimicking Oracle's GREATEST() and LEAST() with the VALUES clause

The values clause can be used to mimick Oracle's greatest and least functions:
create table tq84_data (
  txt varchar(10) primary key,
  n_1 integer,
  n_2 integer,
  n_3 integer
);

insert into tq84_data values ('bar',   7, null,    6);
insert into tq84_data values ('baz',   5,    8,    9);
insert into tq84_data values ('foo',   3,    4,    2);

select
   txt,
  (select max(n) from (values (n_1), (n_2), (n_3) ) as v(n) ) greatest_n,
  (select min(n) from (values (n_1), (n_2), (n_3) ) as v(n) ) least_n
from
   tq84_data
order by
   txt;
--
-- bar   7   6
-- baz   9   5
-- foo   4   2
Github repository about-MSSQL, path: /sql/select/values/greatest-least.sql

Index

Fatal error: Uncaught PDOException: SQLSTATE[HY000]: General error: 8 attempt to write a readonly database in /home/httpd/vhosts/renenyffenegger.ch/php/web-request-database.php:78 Stack trace: #0 /home/httpd/vhosts/renenyffenegger.ch/php/web-request-database.php(78): PDOStatement->execute(Array) #1 /home/httpd/vhosts/renenyffenegger.ch/php/web-request-database.php(30): insert_webrequest_('/notes/developm...', 1759406596, '216.73.216.42', 'Mozilla/5.0 App...', NULL) #2 /home/httpd/vhosts/renenyffenegger.ch/httpsdocs/notes/development/databases/SQL-Server/sql/select/values/greatest-least(58): insert_webrequest() #3 {main} thrown in /home/httpd/vhosts/renenyffenegger.ch/php/web-request-database.php on line 78