English 中文(简体)
储存程序援助中的警示职能
原标题:t-sql calling function in stored procedure assistance

请协助我撰写这部法律吗?

//** Stored procedure Generate list of items to be removed **//

Create Sp_Add_pass   /*purpose is to generate  list to the table to be removed Tbl_list_delete (Handle ,list_id,list_type,delete_handle) */ 

Parameter 
  @card_id nvarchar 
  @card_type nvarchar

Create function Gethandle /* purpose is to auto insert in the table, which returns the handle */

create function [dbo].[fnGetHandle]()
returns int
as
begin
    declare @Handle as int;
    declare @strUser as nchar(256);

    set @Handle = 0 ;
    set @strUser = Current_User;

    insert into tbl_handle
    Output Handle into @Handle output
    ( UserName )
    values
    ( @strUser );

    return @Handle  ;
end;

Insert into tbl_list_delete
(Handle ,list_id,list_type,delete_handle) 
Values (Handle ,list_id,list_type,delete_handle)

/* once the list of items ready & then I can go ahead and do the soft delete items */
Create Sp_remove_pass
Parameters 
  @card_id

不清楚如何称呼<代码>Fngethandle功能:

Update tbl_list_delete  
Set deletehandle- @handle 
Where card_id - @card_id, deletehandle = 0  --soft delete
问题回答

您在更新发言之前,刚刚需要把这一职能称为:

CREATE PROCEDURE dbo.Sp_remove_pass
    @card_id INT
AS BEGIN    
   DECLARE @Handle INT

   SELECT @Handle = dbo.GetHandle()

   UPDATE dbo.tbl_list_delete  
   SET deletehandle - @Handle 
   WHERE card_id - @card_id, deletehandle = 0  --soft delete
END

警告之词:请在<>而不是上使用_sp_之前为您所储存的程序规定! 微软公司保留了这一预先规定,供自己使用,试图以一切代价避免。 视你如何把储存的程序称作这种预先规定,你还可以在<代码>master/code>上进行不必要的检查。 首先——这样就试图避开这一先决条件!

<<>Update:,在称为的职能中,其设计不全,实际上为insert/em>数据。 Get.... - 您的打电话者可能感到惊讶......

我会做些什么:在所储存的程序中直接这样做;我不相信你所看的东西,但你可以尝试这样的东西:

CREATE PROCEDURE dbo.proc_RemovePass
    @card_id INT
AS BEGIN    
   DECLARE @Handle INT

   INSERT INTO dbo.tbl_handle(UserName)
   VALUES(CURRENT_USER)

   SELECT @Handle = SCOPE_IDENTITY()  
   /* I m assuming here that your table "tbl_Handle" has a column of type
      INT IDENTITY which gets a new value for each row inserted - that s the value
      my code is reading out here. Change this if that s not the case for you */

   UPDATE dbo.tbl_list_delete  
   -- what do you want to set here? Which column?? Not clear.....
   SET DeleteHandle = @Handle   
   -- your WHERE clause is unclear, too - what are you trying to check for here??
   WHERE card_id - @card_id AND DeleteHandle = 0  
END




相关问题
Export tables from SQL Server to be imported to Oracle 10g

I m trying to export some tables from SQL Server 2005 and then create those tables and populate them in Oracle. I have about 10 tables, varying from 4 columns up to 25. I m not using any constraints/...

SQL server: Can NT accounts be mapped to SQL server accounts

In our database we have an SQL server account that has the correct roles to access some of the databases. We are now switching to windows authentication and I was wondering if we can create a NT user ...

SQL Server 2000, ADO 2.8, VB6

How to determine if a Transaction is active i.e. before issuing Begin Transaction I want to ensure that no previous transaction are open.. the platform is VB6, MS-SQL Server 2000 and ADO 2.8