Looking at some Stored Procedures for an internally developed app I've yet to have the misfortune of dealing with (but am currently getting ready to migrate my site to) I found something a bit like this*:
ALTER PROCEDURE sp_ADD_USER_ACCOUNT (@UserID VARCHAR(50), @Workstation VARCHAR(50)) AS
-- ...snip...
DO_NUMBER:
-- Generate unique account number
SET @AccountNum = (CAST(DATEPART(ss,GETDATE()) As Varchar(4))+ CAST(DATEPART(hh,GETDATE()) As Varchar(4))+ CAST(DATEPART(dd,GETDATE()) As Varchar(4))+ CAST(DATEPART(yy,GETDATE()) As Varchar(4))+ CAST(DATEPART(mi,GETDATE()) As Varchar(4))+ CAST(DATEPART(mm,GETDATE()) As Varchar(4)))
WHILE (LEN(@AccountNum) < 18)
BEGIN
SET @AccountNum = @AccountNum + '1'
END
Set @Exists=(SELECT AccountNum FROM tblAcc WHERE AccountNum = @AccountNum)
If @Exists IS NOT NULL
BEGIN
GOTO DO_NUMBER
END
-- ...snip...
INSERT INTO tblAcc (AccountNum, ...etc etc)
It's not transactionalised, nor does it try to get an exclusive lock on the table. It functions fine with a single client connected, but sometimes (quite often) it will be called by a few clients in very quick succession. There's no unique constraint on that column (although it being non-unique has some pretty bad side-effects).
More WTFs: the other day someone noticed another procedure called something like sp_MODIFY_ACCOUNT (supposed to modify a single account) included this:
UPDATE tblUserInfo SET ...(every field in table = every passed value from form)... WHERE UserID LIKE '%' & @UserID
(The UserID above is not the same as the account number in the first example, it's a number usually <10000). Changing user number 3052's surname made about 2000 rows of data equal. When asked what they were thinking, the creator of this fine work of art commented "yes, but the % is ignored, because it's doing a full text match".
I've almost convinced them transactions are a good thing, but unique constraints "can cause errors in the software", so I'm going to ride that one out I guess...
*Anonymized, not tested, no doubt a few mistakes in SQL syntax.