sqlserver函数function中不能使用临时表

比如有,如下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

相关文章

SELECT a.*,b.dp_name,c.pa_name,fm_name=(CASE WHEN a.fm_n...
if not exists(select name from syscolumns where name=&am...
select a.*,pano=a.pa_no,b.pa_name,f.dp_name,e.fw_state_n...
要在 SQL Server 2019 中设置定时自动重启,可以使用 Window...
您收到的错误消息表明数据库 'EastRiver' 的...
首先我需要查询出需要使用SQL Server Profiler跟踪的数据库标...