I have to insert a fake column at the result of a query, which is the return value of a table-value function. This column data type must be unique-identifier. The best way (I think...) is to use newid()
function. The problem is, I can't use newid()
inside this type of function:
Invalid use of side-effecting or time-dependent operator in 'newid()' within a function.
4条答案
按热度按时间js4nwp541#
use it as a default instead
NB I used newsequentialid() instead of newid() since newid() will cause pagesplits since it is not sequential, see here: Some Simple Code To Show The Difference Between Newid And Newsequentialid
wecizke32#
You could use ROW_NUMBER function:
SELECT
(ROW_NUMBER() OVER (ORDER BY recordID) ) as RowNumber ,
recordID,
fieldBla1
FROM tableName
Find more information at http://msdn.microsoft.com/pt-br/library/ms186734.aspx
xlpyo6sf3#
Here's a clever solution:
That I can't take credit for. I found it here
lymgl2op4#
You can pass NEWID() as a parameter to your function.
Call the function like this;