Please start any new threads on our new
site at https://forums.sqlteam.com. We've got lots of great SQL Server
experts to answer whatever question you can come up with.
| Author |
Topic |
|
tommynz
Starting Member
9 Posts |
Posted - 2004-08-17 : 04:46:28
|
| Is it possible to find the MAX of two variables (rather than the MAX value in a column)?For exampleDECLARE @V1 int, @V2 int, @V3 intSET @V1 = 1SET @V2 = 2SET @V3 = MAX(@V1, @V2) --??? I know this is wrongWhat should the syntax be? I have searched in Books Online and on the net and not found an example of this.Can anyone help?Many ThanksMichael |
|
|
ditch
Master Smack Fu Yak Hacker
1466 Posts |
Posted - 2004-08-17 : 05:10:06
|
| YOU Can Use CASE:DECLARE @V1 INT, @V2 INT, @V3 INTSET @V1=1SET @V2=2SET @V3 = (SELECT CASE WHEN @V1 > @V2 THEN @V1 ELSE @V2 END)Duane. |
 |
|
|
Kristen
Test
22859 Posts |
Posted - 2004-08-17 : 06:58:07
|
| MAX(@V1, @V2, @V3, ...) would be good, wouldn't it!Kristen |
 |
|
|
ditch
Master Smack Fu Yak Hacker
1466 Posts |
Posted - 2004-08-17 : 07:34:00
|
| No, doesn't look like it:[CODE]declare @v1 intdeclare @v2 intset @v1 = 1set @v2 = 2select max(@v1, @v2)[/CODE]Server: Msg 174, Level 15, State 1, Line 7The max function requires 1 arguments.Duane. |
 |
|
|
Kristen
Test
22859 Posts |
Posted - 2004-08-17 : 08:01:40
|
Yeah, I know. I was dreaming ....SELECT MAX(foo.bar)FROM( SELECT @v1 AS bar UNION ALL SELECT @v2 UNION ALL SELECT @v3) foo looks so ugly, don't you think?Kristen |
 |
|
|
ditch
Master Smack Fu Yak Hacker
1466 Posts |
Posted - 2004-08-17 : 08:13:35
|
Yeah!F U B A R Duane. |
 |
|
|
tommynz
Starting Member
9 Posts |
Posted - 2004-08-18 : 03:29:07
|
| Great, thank you for your help Kristen and DuaneMichael |
 |
|
|
|
|
|
|
|