Results 1 to 3 of 3

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

  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

  2. #2
    Fanatic Member Graff's Avatar
    Join Date
    Jan 2002
    Location
    Calgary
    Posts
    668

    Re: how to return value from SQL 2k5 SPs

    I haven't done too much in this regard but the following link should get you started on the right path

    http://www.sqlteam.com/article/store...returning-data
    If wishes were fishes we'd all cast nets.

  3. #3
    PowerPoster techgnome's Avatar
    Join Date
    May 2002
    Posts
    34,687

    Re: how to return value from SQL 2k5 SPs

    For starters, this won't work:
    if @p_cateno<>'' or @p_cateno<>null

    If should be

    IF ISNULL(@p_cateno, '') <> '' ...


    Secondly, I don't know why you want to return a recordset.... you're not returning one now...

    Lastly, if you modify the end of your query, you could return a value for success, failure, or not found...
    Code:
    	if @@error <> 0
    	  begin
    		rollback transaction
    		return 1 -- This will tell you that it was rolled back
    	  end
    
    	commit transaction
            return 0 -- This will tell you that it succeeded
    end
    Return -1 -- This will tell you that the record was not found
    END

    -tg
    * I don't respond to private (PM) requests for help. It's not conducive to the general learning of others.*
    * I also don't respond to friend requests. Save a few bits and don't bother. I'll just end up rejecting anyways.*
    * How to get EFFECTIVE help: The Hitchhiker's Guide to Getting Help at VBF - Removing eels from your hovercraft *
    * How to Use Parameters * Create Disconnected ADO Recordset Clones * Set your VB6 ActiveX Compatibility * Get rid of those pesky VB Line Numbers * I swear I saved my data, where'd it run off to??? *

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