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

  • Home
  • SEARCH
  • 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 908279
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T16:41:26+00:00 2026-05-15T16:41:26+00:00

I want to check table PREMIUM_SERVICE_USER if any records exists for strClientID update timeValid

  • 0

I want to check table PREMIUM_SERVICE_USER if any records exists for
strClientID update timeValid for +30 if no records for strClientID insert to premium_service_user table.

What am I doing wrong?

It increases timeValid for +30 days but inserts another row too.

SELECT @pre_var = count(*) 
FROM PREMIUM_SERVICE_USER 
WHERE strClientID = @strClientID

/* bronze premium - 200 cash */
IF @Premium = 1
BEGIN
    INSERT INTO PREMIUM_SERVICE_USER 
        (strClientID, timeReg, timeValid, bCurrent, durum) 
    VALUES 
        (@strClientID,getdate(),getdate() + 30,'1','1')

    UPDATE TB_USER 
    SET cash = cash+200 
    WHERE strAccountID = @strClientID
END

IF @Premium = 1 AND @pre_var = 1
BEGIN
    UPDATE PREMIUM_SERVICE_USER 
        SET timevalid = timevalid+30 where strClientID = @strClientID
    UPDATE PREMIUM_SERVICE_USER 
        SET bCurrent = 1 where strClientID = @strClientID
    UPDATE TB_USER 
        SET cash = cash+200 WHERE strAccountID = @strClientID
END
  • 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-05-15T16:41:27+00:00Added an answer on May 15, 2026 at 4:41 pm

    Your problem was running the first if without regard to the value of @pre_var.

    This is a slightly different way of doing it which will be slightly more efficient if PREMIUM_SERVICE_USER is large.

    if @Premium = 1
      begin
        if exists(Select 1 From PREMIUM_SERVICE_USER Where strClientID = @strClientID)
          BEGIN
            update PREMIUM_SERVICE_USER set timevalid = timevalid+30 where strClientID = @strClientID
            update PREMIUM_SERVICE_USER set bCurrent = 1 where strClientID = @strClientID
            UPDATE TB_USER SET cash = cash+200 WHERE strAccountID = @strClientID
           END
        ELSE
          BEGIN
            INSERT INTO PREMIUM_SERVICE_USER (strClientID, timeReg, timeValid, bCurrent, durum) VALUES (@strClientID,getdate(),getdate() + 30,'1','1')
            UPDATE TB_USER SET cash = cash+200 WHERE strAccountID = @strClientID
           END
      end
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Say I want to check if a record in a MySQL table exists. I'd
I want to check whether a Tag (Case-Sensitive) exists in SQL Server 2005 table
I want to check in a table table1 number of records with sno =
I want to check wether a table named basestation exists in a MySQL table
I want to check if a table with a specific name exists in a
I want to efficiently check if a table contains any rows that match <condition
I have a mysql table, I want to check if a row exists where
I want to check if a table body ( tbody ) is empty using
I want to check for the existence of a table with a given ID
I want to check in Transact SQL if a specific column in a table

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.