Trying to SELECT
and UPDATE
a record inside a SELECT
statement.
The Initial SELECT:
INSERT INTO dbo.ATable(VALUE1, VALUE2)
SELECT B.VALUE1, dbo.FUNCTION(B.VALUE1)
FROM dbo.BTable B
The FUNCTION:
SELECT @nextNum = C.VALUE2
FROM dbo.CTABLE C
WHERE C.VALUE1= @VALUE1
RETURN @nextNum
What I am trying to do:
- Insert a record into Table1.
- Get data from Table2.
- Also get a value for VALUE2 from another Table(CTable).
Problem:
I need to increment VALUE2
each time this function executes so multiple calls to that record have a unique value.
I can't have a stored proc from inside the function, I can't have a stored proc inside the SELECT
, and I can't call UPDATE
from inside the FUNCTION
.
Am I out of options? Do I need a different implementation?