Dear
How can I use aggregate function or something like that among columns? e.g.,
columnA, columnB
set @.varC=something
I would like to compare the three values and select max or min value.
Something like,
select max(columnA, columnB, @.varC) from Table
DDL
---
drop table t1
go
create table t1 (d1 varchar(8), d2 varchar(8))
insert into t1 values(
convert(varchar(8), getdate()+1, 112),
convert(varchar(8), getdate()-1, 112)
)
declare @.a varchar(8)
set @.a=convert(varchar(8), getdate(), 112)
select d1, d2, @.a a from t1
---
I am using sql2005. At least I can do that with Xquery. But I want that
without X.
select x.query('
for $a in (sql:column("d1"), sql:column("d2"), sql:variable("@.a"))
order by $a
return $a
') from t1
Pohwan Han. Seoul. Have a nice day.Oracle has a GREATEST() function, but you have to use a CASE expression
in T-SQL. :
CASE WHEN @.a >= @.b AND @.a >= @.c
THEN @.a
WHEN @.b >= @.c AND @.b >= @.a
THEN @.b
WHEN @.c >= @.b AND @.c >= @.a
THEN @.c ELSE NULL END|||Thank CELKO. Exactly, what I wanted. I guess that shows better performance
than mine.
Pohwan Han. Seoul. Have a nice day.
"--CELKO--" <jcelko212@.earthlink.net> wrote in message
news:1125888892.847762.156330@.g47g2000cwa.googlegroups.com...
> Oracle has a GREATEST() function, but you have to use a CASE expression
> in T-SQL. :
> CASE WHEN @.a >= @.b AND @.a >= @.c
> THEN @.a
> WHEN @.b >= @.c AND @.b >= @.a
> THEN @.b
> WHEN @.c >= @.b AND @.c >= @.a
> THEN @.c ELSE NULL END
>
No comments:
Post a Comment