Note that there are some explanatory texts on larger screens.

plurals
  1. POwriting Insert statement in a Stored Procedure
    primarykey
    data
    text
    <p>I have 2 sql table</p> <pre><code>[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 </code></pre> <p>A ContractID has 6 or 12 installments for this i used installmentNum column for insertion through a winform i write this stored procedure</p> <pre><code>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&lt;&gt;0 and @iupdate=0 //i'm confused here BEGIN INSERT INTO [dbo].[Installment] VALUES(@InstallmentNumber,@month,@installment,@commission) END if @ContractID &lt;&gt;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 </code></pre> <p>second for reading installments one by one of selected contract i'm trying to write this stored procedure</p> <pre><code>ALTER PROCEDURE [dbo].[spReadInstallment] @ContractID int = 0 AS SET NOCOUNT ON SET XACT_ABORT ON BEGIN tran if @ContractID&lt;&gt;0 begin tran BEGIN SELECT ContractID, InstallmentNumber, currentMonth, installment, commission FROM Installment WHERE (ContractID = @contractid) // have doubt about the select statement? END commit </code></pre> <p>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</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload