Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/sql-server/25.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Sql 使用派生列插入EXEC xp_目录树_Sql_Sql Server_Tsql_Sql Server 2016 - Fatal编程技术网

Sql 使用派生列插入EXEC xp_目录树

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

我尝试使用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 #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并不是查询文件系统的正确工具。