Sql 使用派生列插入EXEC xp_目录树
我尝试使用xp_dirtree存储过程在SSRS报告中创建完整的文件路径,使用:Sql 使用派生列插入EXEC xp_目录树,sql,sql-server,tsql,sql-server-2016,Sql,Sql Server,Tsql,Sql Server 2016,我尝试使用xp_dirtree存储过程在SSRS报告中创建完整的文件路径,使用: CREATE TABLE #tt1 ( id int IDENTITY(1,1) ,subdirectory nvarchar(512) ,depth int ,isfile bit); INSERT #tt1 EXEC xp_dirtree @dir, 10, 1 但是,作为补充,我想在存储过程顶部的insert中添加一列。大概是 CREATE TABLE
CREATE TABLE #tt1 (
id int IDENTITY(1,1)
,subdirectory nvarchar(512)
,depth int
,isfile bit);
INSERT #tt1
EXEC xp_dirtree @dir, 10, 1
但是,作为补充,我想在存储过程顶部的insert中添加一列。大概是
CREATE TABLE #tt1 (
id int IDENTITY(1,1)
,subdirectory nvarchar(512)
,depth int
,isfile bit
,NewColumn nvarchar(100)
);
INSERT #tt1
EXEC xp_dirtree @dir, 10, 1, 'NEW COLUMN'
然而,这不起作用,并踢出
Msg 213, Level 16, State 7, Procedure xp_dirtree, Line 1 [Batch Start Line 0]
Column name or number of supplied values does not match table definition.
您需要在使用
插入到..时修复列代码>语句:
INSERT INTO #tt1 (subdirectory, depth, isfile, NewColumn)
EXEC xp_dirtree @dir, 10, 1, 'NEW COLUMN'
@XDSA5286。因为SP
返回的列少于或多于中指定的列列表插入到
语句中的列。简短回答-您不能直接这样做。这是存储过程工作方式的限制—结果集在过程中定义。对于您发布的情况,有一些变通方法。然而,tsql并不是查询文件系统的正确工具。