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.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 Min of two value

Author  Topic 

Ali Reza Pooneh
Starting Member

14 Posts

Posted - 2010-04-17 : 12:06:09
Hi.
I have a stored proc that run about 10 times in one second!
I want to write it by top performance.
I want to:

Update Prices set(Low, High) Values (Min(Low,@newPrice), Max(High, @newPrice)) where (...)

But Min and Max methods work on select query. please help me to write it. Notice that i don't want to write if and else statement.
Thanks.

Kristen
Test

22859 Posts

Posted - 2010-04-17 : 12:23:26
[code]
UPDATE U
SET Low = CASE WHEN Low < @newPrice THEN Low ELSE @newPrice END,
High = CASE WHEN High > @newPrice THEN High ELSE @newPrice END
FROM Prices AS U
WHERE (@newPrice < Low OR @newPrice > High) -- Only update rows where there will actually be a change
AND ... other conditions
[/code]
Go to Top of Page
   

- Advertisement -