newid() inside sql server function

后端 未结 4 2282
旧巷少年郎
旧巷少年郎 2020-11-27 03:24

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 (

4条回答
  •  情深已故
    2020-11-27 04:13

    here's a clever solution:

    create view getNewID as select newid() as new_id
    
    create function myfunction ()
    returns uniqueidentifier
    as begin
       return (select new_id from getNewID)
    end
    

    that i can't take credit for. i found it here: http://omnibuzz-sql.blogspot.com/2006/07/accessing-non-deterministic-functions.html

    -don

提交回复
热议问题