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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T02:10:35+00:00 2026-05-25T02:10:35+00:00

This is probably more of a best practices question than a true code question.

  • 0

This is probably more of a “best practices” question than a true code question.

I have a stored procedure to update a table, but needs a couple of values from another table.

the first two selects get the value from the table and then are used in the update statement.

The select statments:

 Select @iStatusDropDownValueID = iDropDownValueID
        From DropDownValue
        Inner Join DropDownValueType On DropDownValue.iDropDownValueTypeID = DropDownValueType.iDropDownValueTypeID
        Where DropDownValueType.vchDropDownValueTypeName = 'Status'
        AND DropDownValue.vchDropDownValueName = 'Scheduled'
        AND DropDownValue.tiRecordStatus = 1
        And DropDownValueType.tiRecordStatus = 1

 Select @iLastStatusDropDownValueID = iDropDownValueID
        From DropDownValue
        Inner Join DropDownValueType On DropDownValue.iDropDownValueTypeID = DropDownValueType.iDropDownValueTypeID
        Where DropDownValueType.vchDropDownValueTypeName = 'Status'
        AND DropDownValue.vchDropDownValueName = 'CriticalErrorOccurred'
        AND DropDownValue.tiRecordStatus = 1
        And DropDownValueType.tiRecordStatus = 1

The Update statement:

Update Schedule
    Set
        iStatusDropDownValueID = @iStatusDropDownValueID,
        iLastStatusDropDownValueID = @iLastStatusDropDownValueID,
        iCurrentLogID = @iCurrentLogID,
        dtNextDate = @dtNextDate,
        dtLastDate = @dtLastDate,
        iRetryCount = @iRetryCount,
        iFailedCount = @iFailedCount,
        iBusyRetryCount = @iBusyRetryCount,
        vchUpdateBy = @vchUpdateBy,
        dtUpdateDate = @dtLastDate
    WHERE
        iScheduleID = @iScheduleID

First, the values that are retrieved by the first two select statements are always the same. So they could be passed in by the code itself. I don’t know that this will speed things up at all, just make the entire stored procedure better and easier to read.

Second, if the “Value Name” should change this store procedure will break (which is possible, but not often).

I am looking for any insight into the Best Practices for this situation.

  • 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-25T02:10:36+00:00Added an answer on May 25, 2026 at 2:10 am

    Personally I always declare my variables and don’t use @vars.
    @vars are like variants, they don’t protect you against typos.
    If you use explicitly declared variables, MySQL will warn you against typos and your vars will be typed making your intentions clearer and your code slightly faster.

    CREATE PROCEDURE (IN a INTEGER) 
    BEGIN
      DECLARE var1 INTEGER;
      DECLARE var2 INTEGER;
      DECLARE initialized_var INTEGER DEFAULT 0;
    
      SET var = 1;  //to just set a var.
      SELECT myfield INTO var2 FROM atable WHERE a <> atable.b ORDER BY b LIMIT 1;
      //Always use `limit 1` here.
      //use `select into ...order by .. limit 1` to make you queries repeatable.
      //The limit 1 also speeds up things a bit.
      //make sure to test SELECT INTO vars against `null`  
      IF var2 IS NULL THEN .....
    

    If you need to use the outcome of one stored procedure, why not make a stored function.

    CREATE FUNCTION pi RETURNS float
    BEGIN
       RETURN 3.14;
    END $$
    

    Then you can just write a query like:

    INSERT INTO atable (math_constants) VALUES (pi());
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

This probably has a simple answer, but I must not have had enough coffee
This probably sounds really stupid but I have noo idea how to implement jquery's
This is probably a common Objective-C question reported by Java coders, but I don't
This is probably a very stupid question, but I am just not sure which
This is probably real simple, but I don't know best way to do this.
This is probably explained more easily with an example. I'm trying to find a
This probably sounds like a terrible idea at first glance, but here is my
I know this probably really simple but Im not sure what im doing wrong...
I am using ASP.Net MVC but this probably applies to all MVC patterns in
Okay, so this probably sounds terribly nefarious, but I need such capabilities for my

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.