Results 1 to 3 of 3

Thread: [RESOLVED] how to return value from SQL 2k5 SPs

Threaded View

  1. #1

    Thread Starter
    Fanatic Member
    Join Date
    Jul 2007
    Posts
    617

    Resolved [RESOLVED] how to return value from SQL 2k5 SPs

    here the snipset how i insert row to tbldtr
    1. first its search for the employee number pass by variable @prm_empno
    2. if the employee basically it wont insert row in tbldtr as defined by
    IF statement

    now what i am trying to work if ever there will be no match of employee
    is to send something to recordset set that the employee did not exist in the
    master employee table.
    Code:
    USE [dbname]
    GO
    /****** Object:  StoredProcedure [dbo].[add_todtr]    Script Date: 08/01/2007 09:51:39 ******/
    SET ANSI_NULLS ON
    GO
    SET QUOTED_IDENTIFIER ON
    GO
    
    ALTER PROCEDURE [dbo].[add_todtr]
    	-- Add the parameters for the stored procedure here
    @prm_tradeno nvarchar(10),
    @prm_empno nvarchar(10),
    @prm_ccno nvarchar(10),
    @prm_tiAM nvarchar(10),
    @prm_toAM nvarchar(10),
    @prm_tiPM nvarchar(10),
    @prm_toPM nvarchar(10),
    @prm_Remarks nvarchar(50),
    @prm_dtfile nvarchar(20),
    @prm_deviceno nvarchar(10),
    @prm_dtmigrate nvarchar(20)
    
    
    
    
    AS
    declare @p_cateno nvarchar(10), @p_firmno nvarchar(10)
    BEGIN
    
    -- check if employee no is in employee master 
    --table
    select @p_cateno=fk_cateno, @p_firmno=fk_firmno from tblemployee
    where pk_empno=@prm_empno
    
    if @p_cateno<>'' or @p_cateno<>null
    	begin
    	begin transaction
    
    	insert into tbldtr(
    				fk_empno,
    				dtmigrate,
    				dtfile,
    				fk_cateno,
    				fk_ccno,
    				fk_tradeno,
    				fk_firmno,
    				deviceno,
    				TI_AM,
    				TO_AM,
    				TI_PM,
    				TO_PM,
    				Remarks)
    	values(
    		@prm_empno,
    		@prm_dtmigrate,
    		@prm_dtfile,
    		@p_cateno,
    		@prm_ccno,
    		@prm_tradeno,
    		@p_firmno,
    		@prm_deviceno,
    		@prm_tiAM,
    		@prm_toAM,
    		@prm_tiPM,
    		@prm_toPM,
    		@prm_Remarks
    
    	)
    	if @@error <> 0
    	  begin
    		rollback transaction
    		return
    	  end
    
    	commit transaction
    end
    END
    Last edited by si_the_geek; Aug 1st, 2007 at 11:15 AM. Reason: added code tags

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width