【问题标题】:Insert Into EXEC xp_dirtree with derived column使用派生列插入 EXEC xp_dirtree
【发布时间】:2020-01-30 09:46:44
【问题描述】:

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

【问题讨论】:

  • 简短回答 - 你不能直接这样做。这是存储过程工作方式的一个限制——结果集是在过程中定义的。您发布的情况有解决方法。但是,tsql 确实不是询问文件系统的正确工具。

标签: sql sql-server tsql sql-server-2016


【解决方案1】:

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

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

【讨论】:

  • @XDSA5286。 . .这是因为SP 返回的列少于或多于INSERT INTO 语句中指定的列列表。
猜你喜欢
  • 2020-07-16
  • 1970-01-01
  • 1970-01-01
  • 2020-05-23
  • 2017-04-19
  • 2021-06-19
  • 2013-01-15
  • 2020-12-01
  • 1970-01-01
相关资源
最近更新 更多