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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T08:00:33+00:00 2026-06-07T08:00:33+00:00

I have two tables: 1) BlogPost: COLUMN_NAME DATA_TYPE Id int Title varchar Description varchar

  • 0

I have two tables:

1) BlogPost:

 COLUMN_NAME    DATA_TYPE
Id                  int
Title             varchar
Description       varchar
ImageName         varchar
FileName          varchar
CreatedDate       datetime
Tags              varchar
ModifiedDate      datetime
RateNumber           int
CreatedBy            int
ShortDescription    varchar

2. BlogRating:

Id  EmployeeId  PostId  Rate
4     1           12    3
5     1           13    2
6     1           11    2

I wrote a stored procedure to Save the details of BlogRating:

ALTER PROCEDURE [dbo].[BlogRatingSave]
     @EmployeeId    int
    ,@PostId        int
    ,@Rate          int
AS
BEGIN
    DELETE FROM [HRM_BlogRating]
        WHERE   [HRM_BlogRating].[EmployeeId] = @EmployeeId 
            AND [HRM_BlogRating].[PostId] = @PostId 

    INSERT INTO [HRM_BlogRating]
        ([EmployeeId]
        ,[PostId]
        ,[Rate]
        )
    VALUES
        (@EmployeeId    
        ,@PostId        
        ,@Rate
        )
END

What I want is that If different employees give rate, while saving BlogRating I need to auto increment the field RateNumber in table1by 1. At the same time if same employee rates next time there should not an increment for RateNumber. Please help me to solve 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-07T08:00:37+00:00Added an answer on June 7, 2026 at 8:00 am

    Why are you deleting and then inserting. Instead you should try to insert and if it fails (due to a duplicate) then do an update.

    In the process you can also adjust the value of the rating, but I assume you will need to pass in the EmployeeId of the person making the change since that is part of your rule. ie.

    update BlogPost set RateNumber = RateNumber + 1 where EmployeeId = @EmployeeID and CreatedBy != @EmployeeID
    

    So it would all become:

    ALTER PROCEDURE [dbo].[BlogRatingSave]
         @EmployeeId    int
        ,@PostId        int
        ,@Rate          int
    AS
    BEGIN
        BEGIN TRY
            INSERT INTO [HRM_BlogRating]
                ([EmployeeId]
                ,[PostId]
                ,[Rate]
                )
            VALUES
                (@EmployeeId    
                ,@PostId        
                ,@Rate
                )
        END TRY
        BEGIN CATCH
            UPDATE [HRM_BlogRating]
                 SET Rate = @Rate
            WHERE EmployeeID = @EmployeeID and PostId = @PostId
        END CATCH
    
        UPDATE BlogPost set RateNumber = RateNumber + 1 where EmployeeId = @EmployeeID and CreatedBy != @EmployeeID
    END
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have two tables: 1) BlogAlbum: Id AlbumName CoverPhoto CreatedDate Description 1 Onam noImage.jpg
I have two tables with this structure: Table one: ID Description Table two: ID
I have two tables CREATE TABLE table1 (id int primary key auto_increment,....); CREATE TABLE
I have two tables. threads with the columns ID, forumID, title, content, unixtime comments
We have two Tables: Document: id, title, document_type_id, showon_id DocumentType: id, name Relationship: DocumentType
i have two tables products and reviews each product has several reviews linked by
I have two tables : teachers (teacher_id,teacher_name) courses (teacher_id,course_id) And I need to display
I have two tables on a webform. On a button click I want to
i have two tables both are related with primary-foreign key ralation and i have
I have two tables, the first has a primary key that is an identity,

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.