Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8372815
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T14:31:53+00:00 2026-06-09T14:31:53+00:00

I wrote a stored procedure for updating a record which satisfies certain condition. I

  • 0

I wrote a stored procedure for updating a record which satisfies certain condition. I want to check if the passed value is contained in the table. I am using

declare @disp_sname varchar(100);
declare @disp_type varchar(100);
declare @disp_sub_type varchar(100);
declare @disp_date date;

select @disp_sname= voucher_sname,@disp_type=voucher_type,
@disp_sub_type=voucher_sub_type,@disp_date=voucher_date
from voucher_master

which is returning just the last row value.

My entire stored procedure is

    USE [new_esatnam]
GO
/****** Object:  StoredProcedure [dbo].[spUpdateVoucherNo]    Script Date: 08/13/2012 13:36:24 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO

ALTER PROCEDURE [dbo].[spUpdateVoucherNo] 
(
@voucher_id as int,
@voucher_separate_numbering as varchar(2),
@voucher_method_numbering as varchar(2),
@voucher_last_number as int,
@voucher_sname as varchar(15),
@voucher_type as varchar(2),
@voucher_sub_type as varchar(2),
@voucher_date as datetime,
@company_code as varchar(50),
@updated_by as int,
@updated_on as datetime
)   
AS
BEGIN
SET NOCOUNT ON;
declare @disp_sname varchar(100);
declare @disp_type varchar(100);
declare @disp_sub_type varchar(100);
declare @disp_date date;

select @disp_sname= voucher_sname,@disp_type=voucher_type,
@disp_sub_type=voucher_sub_type,@disp_date=voucher_date
from voucher_master

if @disp_sname=@voucher_sname and @disp_type=@voucher_type and @disp_sub_type=@voucher_sub_type and @disp_date!=@voucher_date
BEGIN
update voucher_master set voucher_type=@voucher_type,voucher_sub_type=@voucher_sub_type,
voucher_sname=@voucher_sname,
voucher_separate_numbering=@voucher_separate_numbering,
voucher_method_numbering=@voucher_method_numbering,
voucher_date=@voucher_date,
voucher_last_number=@voucher_last_number,
company_code=@company_code,
updated_by=@updated_by,
updated_on=@updated_on where voucher_id=@voucher_id 
END
if @disp_sname!=@voucher_sname
BEGIN
update voucher_master set voucher_type=@voucher_type,voucher_sub_type=@voucher_sub_type,
voucher_sname=@voucher_sname,
voucher_separate_numbering=@voucher_separate_numbering,
voucher_method_numbering=@voucher_method_numbering,
voucher_date=@voucher_date,
voucher_last_number=@voucher_last_number,
company_code=@company_code,
updated_by=@updated_by,
updated_on=@updated_on where voucher_id=@voucher_id 
END

return @@ROWCOUNT
END

I want my stored procedure to satisfy this condition

 voucher_type    voucher_sub_type     date        voucher_sname
 INV                DOM              1/1/2000       ID            allowed
 INV                DOM              15/1/2000      ID            allowed

 INV                INT              1/1/2000       ID            not allowed
 INV                INT              15/3/2012      ID            not allowed

Voucher Sname should be allowed for same voucher_type and voucher_sub_type with different date and the same voucher_sname should not be allowed for different combination of voucher_type and voucher_sub_type.

Any ideas how my sp will satify this?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-09T14:31:54+00:00Added an answer on June 9, 2026 at 2:31 pm

    just use this in your first aql query –voucher_id=@voucher_id

        ALTER PROCEDURE [dbo].[spUpdateVoucherNo] 
            (
            @voucher_id as int,
            @voucher_separate_numbering as varchar(2),
            @voucher_method_numbering as varchar(2),
            @voucher_last_number as int,
            @voucher_sname as varchar(15),
            @voucher_type as varchar(2),
            @voucher_sub_type as varchar(2),
            @voucher_date as datetime,
            @company_code as varchar(50),
            @updated_by as int,
            @updated_on as datetime
            )   
            AS
            BEGIN
            SET NOCOUNT ON;
            declare @disp_sname varchar(100);
            declare @disp_type varchar(100);
            declare @disp_sub_type varchar(100);
            declare @disp_date date;
    
    DECLARE @minid int,@maxid int
    select @minid=min(voucherid),@maxid=max(voucherid) from voucher_master 
    
    while(@minid <= @maxid)
    BEGIN
            select @disp_sname= voucher_sname,@disp_type=voucher_type,
            @disp_sub_type=voucher_sub_type,@disp_date=voucher_date
            from voucher_master where voucher_id=@minid
    
            if @disp_sname=@voucher_sname and @disp_type=@voucher_type and @disp_sub_type=@voucher_sub_type and @disp_date!=@voucher_date
            BEGIN
            update voucher_master set voucher_type=@voucher_type,voucher_sub_type=@voucher_sub_type,
            voucher_sname=@voucher_sname,
            voucher_separate_numbering=@voucher_separate_numbering,
            voucher_method_numbering=@voucher_method_numbering,
            voucher_date=@voucher_date,
            voucher_last_number=@voucher_last_number,
            company_code=@company_code,
            updated_by=@updated_by,
            updated_on=@updated_on where voucher_id=@voucher_id 
            END
            if @disp_sname!=@voucher_sname
            BEGIN
            update voucher_master set voucher_type=@voucher_type,voucher_sub_type=@voucher_sub_type,
            voucher_sname=@voucher_sname,
            voucher_separate_numbering=@voucher_separate_numbering,
            voucher_method_numbering=@voucher_method_numbering,
            voucher_date=@voucher_date,
            voucher_last_number=@voucher_last_number,
            company_code=@company_code,
            updated_by=@updated_by,
            updated_on=@updated_on where voucher_id=@voucher_id 
            END
    
    SET @minid=@minid+1
    END
    
    END
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to write a stored procedure to increment the value of an int
In Sql Server 2005, I have a stored procedure, in which i have wrote
I wrote a stored procedure which returns contract status for anauthor. If author doesn't
I wrote a stored-procedure in Oracle and now, I want to launch it in
I wrote a stored procedure and created a temp table #TempHitRatioTable. I forgot to
I wrote a stored procedure to return the record but as soon as I
Someone in my company wrote a closed stored procedure which gives these results: rowNumber
I wrote a stored procedure and want to execute it within a Rake task.
I wrote the following stored procedure, in which I use a local variable 'syncParam':
here's the stored procedure i wrote.In this proc p_subjectid is an array of numbers

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.