October 27, 2009 at 1:10 am
I have a table and that is having some three column and some 3 rows.
So if we query on select column like Min(Column1), Min(Column2) then we will get column wise min result.
But i want that what is the min row that particular row.
Please help.
October 27, 2009 at 1:21 am
Can you give us table script, test data and expected result? In the below format.
Create table ...
INSERT INTO ....
Expected REsult....
---------------------------------------------------------------------------------
October 27, 2009 at 1:21 am
Hi,
Assumption of min value among the columns in the each row
try this
declare @A123 table
(
ID int,
col1 int,
col2 int,
col3 int
)
insert into @A123
SELECT 1, 1, 2, 3
UNION
SELECT 2, 6, 5, 4
UNION
SELECT 3, 7, 8, 9
SELECT * FROM @A123
SELECT
ID,
(CASE WHEN col1 <= col2 AND col1 <= col3 then col1
WHEN col2 <= col3 THEN col2
ELSE col3
END) Min_val
FROM @A123
October 27, 2009 at 1:27 am
Thx, I got the excepted result.
Viewing 4 posts - 1 through 3 (of 3 total)
You must be logged in to reply to this topic. Login to reply