[font="Verdana"]The way I would do this is to keep the counter in a separate table, and use an identity field on that table as the counter.
However, if you combine your two queries, and use a suffiently high isolation level, it should also do the trick:
--
-- if there is no trigger on your Event table, then use the following
-- logic to get the next counter
--
update Quantifi.dbo.DocDataEvent
set @OrgEventCounter = OrgEventCounter = OrgEventCounter + 1
where OrganizationID = 2325 and
DocumentTypeOrgID = 1
--
-- assuming you have a trigger on the Event table that updates the
-- counter in the Quantifi.dbo.DocDataEvent table
--
set transaction isolation level serializable
begin transaction;
insert into dbo.Event(
OrganizationID,
TypeID,
OrgEventCounter
)
select 1234,
1,
max(OrgEventCounter) + 1
from Quantifi.dbo.DocDataEvent
where OrganizationID = 2325 and
DocumentTypeOrgID = 1;
commit;
[/font]