比如有,如下function
CREATE FUNCTION dbo.functionName( @id INT,@type VARCHAR(20) ) RETURNS TABLE AS BEGIN CREATE TABLE #Temporary_table_name ( t_id INT NOT NULL ) END
这样写完,run之后会抱错的:Cannot access temporary tables from within a function.
或许sqlserver db就是这样设计的,让我们如果遇到复杂的逻辑,需要使用临时表的时候,去使用存储过程写。
有简单的逻辑,避免使用临时表,去用函数实现。
参考url:http://stackoverflow.com/questions/9561626/cannot-access-temporary-tables-from-within-a-function