I have a table where I'd like to set two of its columns' default values to the same value. I'm using a SQL function which generates a unique value. I can set a column default for one of the columns easily enough using the function:
[PreCode] NVARCHAR(20) NOT NULL DEFAULT([dbo].GetPreCode()),
But how would I use the same value in my other column? I'd assume that if I used the same syntax as above for the other column that the function would generate another unique value instead of using the value that was generated for the first column. How can I get both columns to have the same default value from a single call to the SQL function?
sys.dm_tran_current_transactionin the function, but it's probably far more sane to do this in the code that performs the actual inserts, wrap it in a stored procedure, or use anAFTER INSERTtrigger.