期待

时间:2016-05-23 21:26:05

标签: sql sql-server sql-server-2008

我有这个代码块,我不确定如何在执行时修复错误。

IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[Dan_IPro_to_II]') AND type in (N'P', N'PK'))
    DROP PROCEDURE [dbo].[Dan_IPro_to_II]
GO

CREATE PROCEDURE Dan_IPro_to_II 
    @ipro_db SYSNAME,
    @ipro_setid int,
    @II_setid int
AS
BEGIN
   SET NOCOUNT ON;

   DECLARE @table_name SYSNAME
   Declare @table_part VARCHAR(30)
   Declare @db SYSNAME

   DECLARE comp_cursor CURRSOR FOR
      SELECT TABLE_NAME 
      FROM INFORMATION_SCHEMA.TABLES
      WHERE TABLE_TYPE = 'BASE TABLE'
        AND TABLE_NAME LIKE '%' + @ipro_setID + '' 
      ORDER BY TABLE_NAME

   OPEN COMP_CURSOR

   FETCH NEXT FROM COMP_CURSOR INTO @table_name

   SET @table_part = 'IPro_' + replace(@table_name,'_' + @ipro_setID,'')

   WHILE (@@fetch_status = 0 and @@error = 0 )
   BEGIN
        print 'Copying ' + @table_name

        EXEC ('if exists (select Table_Name from information_schema.tables where    table_name = ''' + @table_part + ''' ) DROP TABLE ' + @table_part )
        EXEC ('select * into ' + @table_part + ' FROM [' + @ipro_db + '].[dbo].' + @table_name  )

        FETCH NEXT FROM COMP_CURSOR INTO @table_name
    END

    print 'Completed Ipro Transfer ' +@db

    CLOSE COMP_CURSOR
    DEALLOCATE COMP_CURSOR
END
GO

这是我执行存储过程时遇到的错误:

  

Msg 201,Level 16,State 4,Procedure Dan_IPro_to_II,Line 0
  过程或函数'Dan_IPro_to_II'需要参数'@ipro_db',这是未提供的。

我想告诉它在哪里找到@Ipro_db,我想?我会把它放在哪里?在存储过程的执行语句中?

感谢您的帮助。

我尝试将它们导入导入或导出数据,但他们没有知道如何操作的人。他们想要这样。

再次感谢您的帮助。

VBNewbie。

2 个答案:

答案 0 :(得分:0)

尝试这样,我在代码中更改了一些内容。包含转换函数到Int参数。关键字光标拼写错误。

 <?php foreach ($user as $user): ?> 
 <tr> 
 <td><?= $this->Time->format($user->modified, date('d-m-Y')) ?></td> 
 </tr>

答案 1 :(得分:0)

这是我解决这个问题的方法。感谢@StackNewUser帮助解决这个问题。

USE [ImpactPro90]
开始 SET NOCOUNT ON;

DECLARE @table_name SYSNAME
DECLARE @table_part SYSNAME

DECLARE comp_cursor cursor FOR
    SELECT TABLE_NAME FROM INFORMATION_SCHEMA.TABLES
    WHERE TABLE_TYPE = 'BASE TABLE'
    AND TABLE_NAME  LIKE '%_1604220600'  
ORDER BY TABLE_NAME

OPEN COMP_CURSOR

FETCH NEXT FROM COMP_CURSOR INTO @table_name
    SET @table_part = 'IPro_' + @table_name 
    WHILE (@@fetch_status = 0 and @@error = 0 )
BEGIN
   PRINT'Copying table ' + @table_name
   EXEC ('select * into ' +'[II_to_IIRP].[dbo].' + @table_name + ' FROM  [ImpactPro90].[dbo].' + @table_name  )
   PRINT 'Done copying ' + @table_name
   FETCH NEXT FROM COMP_CURSOR INTO @table_name
   PRINT 'Getting next table ' + @table_name

END    关闭COMP_CURSOR    DEALLOCATE COMP_CURSOR    END