I want to get the minimum and maximum across multiple columns in a row. I found various working queries using CROSS APPLY, UPIVOT and VALUES, e.g. like this one:
select column1, column2, code1,
(qty2), (qty3), (qty4), (qty5),
MinVal, MaxVal
from dummydata
cross apply (select MIN(NULLIF (d ,0)) MinVal,
Max(d) MaxVal
FROM (VALUES (qty2),
(qty3),
(qty4),
(qty5)
) AS a(d)
) A
These all are working in SQL Server 2005 or above, but I need a solution for SQL Server 2000 (database compatibility level 80). How can I do that?
DDL:
CREATE TABLE [dbo].[dummydata](
[column1] [nvarchar](255) NULL,
[column2] [nvarchar](255) NULL,
[code1] [nvarchar](255) NULL,
[qty2] [float] NULL,
[qty3] [float] NULL,
.......
[qty20] [float] NULL)
Query output: