首页 > 解决方案 > 使用派生列插入 EXEC xp_dirtree

问题描述

我正在尝试使用 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

但是,作为补充,我想在存储过程顶部的插入中添加一列。所以像

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.

标签: sqlsql-servertsqlsql-server-2016

解决方案


您需要在使用insert into . .语句时修复列:

INSERT INTO #tt1 (subdirectory, depth, isfile, NewColumn)
     EXEC xp_dirtree @dir, 10, 1, 'NEW COLUMN'

推荐阅读