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
 SQL Server 2000 Forums
 SQL Server Development (2000)
 Max function

Author  Topic 

kio
Starting Member

1 Post

Posted - 2009-03-17 : 17:28:52
Hi at all,
i'm new user of this forum
I have this problem
My windows application is a multi-user application on same database sql-server
Inside my database there are 3 tables with a same field (FIELD_A).

Field_A is integer (INT)

Users can insert record inside table_A, table_B, table_C but when insert record i must get
max value from table_A, table_B, table_C , how can i do ?

Then, if i get max value from table_A, table_B, table_C is there possible that another user can get
same max value, before i insert record inside table_A or table_B or table_C ?

Note: Max value must be unique for table_A, table_B, table_C simultaneously

Thank you very much

SwePeso
Patron Saint of Lost Yaks

30421 Posts

Posted - 2009-03-18 : 03:48:57
You can use transactions. Or set a proper ISOLATION LEVEL.
DECLARE	@Max INT

BEGIN TRANSACTION

SELECT @Max = MAX(Field_A)
FROM (
SELECT MAX(Field_A)
FROM Table1

UNION ALL

SELECT MAX(Field_A)
FROM Table2

UNION ALL

SELECT MAX(Field_A)
FROM Table3
) AS f

... Now do something

COMMIT TRANSACTION



E 12°55'05.63"
N 56°04'39.26"
Go to Top of Page
   

- Advertisement -