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 7914515
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T14:08:31+00:00 2026-06-03T14:08:31+00:00

I have 2 sql table [dbo].[Contract] [ContractID] pk,…..other column [dbo].[Installment] //this table has composite

  • 0

I have 2 sql table

[dbo].[Contract]
[ContractID] pk,.....other column

[dbo].[Installment] //this table has composite primary key
[ContractID] pk n fk // it is primary and foreign key
[installmentNum] pk, // contractID and installmentnum both are the primary keys

A ContractID has 6 or 12 installments for this i used installmentNum column for insertion through a winform i write this stored procedure

ALTER PROCEDURE [dbo].[spInsertUpdateInstallment]
@ContractID int = 0,
@InstallmentNumber int = 0,
@month varchar(10),
@installment money = 0.00,
@commission money = 0.00,
@iupdate int = 0
AS
SET NOCOUNT ON 
SET XACT_ABORT ON  
BEGIN TRAN
 if @ContractID<>0 and @iupdate=0 //i'm confused here
BEGIN
INSERT INTO [dbo].[Installment] 
VALUES(@InstallmentNumber,@month,@installment,@commission)
END
if @ContractID <>0 and @month is not null and @iupdate=1
BEGIN
UPDATE [dbo].[Installment] 
SET 
[ContractID] = @ContractID,
[InstallmentNumber] = @InstallmentNumber,
[currentMonth] = @month,
[installment] = @installment,
[commission] = @commission
WHERE [ContractID] = @ContractID and [currentMonth] = @month
END
Commit

second for reading installments one by one of selected contract i’m trying to write this stored procedure

ALTER PROCEDURE [dbo].[spReadInstallment]
@ContractID int = 0
AS
SET NOCOUNT ON 
SET XACT_ABORT ON
BEGIN tran
if @ContractID<>0
begin tran
BEGIN
SELECT     ContractID, InstallmentNumber, currentMonth, installment, commission
FROM         Installment
WHERE     (ContractID = @contractid) // have doubt about the select statement?
END
commit

I have confusion About the SELECT statement of the spReadInstallment and insert statment of the spInsertUpdateInstallment I’m beginer and can’t understand the mistake behind kindly guide me

  • 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-03T14:08:34+00:00Added an answer on June 3, 2026 at 2:08 pm

    if @ContractID<>0 and @iupdate=0 //i'm confused here

    Your first stored procedure is performing an upsert (update or insert) – it will insert or update a table depending on the arguments given for the PK parameters: @ContractID and @iupdate

    When those two both have value 0, then the stored proc will perform an insert. Otherwise, it’ll perform an update to the table.

    Analyse whether you really need all those default values on your parameters here.

    Your second stored procedure, have no doubts. Rewrite it like this without the default value 0 on the @ContractID, and without the unnecessary multiple hanging transactions on a SELECT operation:

    ALTER PROCEDURE [dbo].[spReadInstallment]
    @ContractID int
    AS
    SET NOCOUNT ON;
    
    SELECT    ContractID, InstallmentNumber, currentMonth, installment, commission
    FROM      Installment
    WHERE     ContractID = @contractid;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Lets say I have this SQL statements: ALTER TABLE dbo.[tbl] ALTER COLUMN col1 varchar(300)
So I have a table in SQL Server w/ a primary key column, and
I have this sql: ALTER TABLE dbo.ChannelPlayerSkins DROP CONSTRAINT FK_ChannelPlayerSkins_Channels but apparently, on some
I have this sql statement: CREATE TABLE [dbo].[User]( [UserId] [int] IDENTITY(1,1) NOT NULL, [FirstName]
If i have a sql table with column like this id version subversion 1
I have a sql table of payroll data that has wage rates and effective
I have an SQL table like this : sales(product,timestamp) I want to display a
I have an sql table which has the following rows. (4081, 3, '', 'contrapreneurship.jpg',
So I have this SQL table that I need to update. Now we use
I have a SQL 2005 table consisting of around 10million records (dbo.Logs). I have

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.