|I need a way to return an identity value for a SELECT statement that is guaranteed to be unique.
So I wrote the following stored procedure:
CREATE PROCEDURE agsp_UniqueDocnum
@DOCUMENTTYPE AS NVARCHAR(15),
@ORDERID AS INT
-- SET NOCOUNT ON added to prevent extra result sets from
-- interfering with SELECT statements.
SET NOCOUNT ON;
INSERT INTO ags_UniqueDocnum
ENDThe ags_UniqueDocnum table contains an Identity column that I'm using as the unique identifier.
But when I try:
SELECT agsp_UniqueDocnum('TEST', 0)It tells me that that's not the name of a FUNCTION. So I'm stuck in a catch 22. You can't use an INSERT inside a function, and you can't SELECT a stored procedure!
How can I get a unique identifier within a SELECT statement?
It must be all digits, no alpha, and no more than 16 characters in length.
The difficult we do right away...
...the impossible takes slightly longer.