473,387 Members | 1,512 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

How do I use constants in stored procedures?

I have several instances of "magic number" variables (tinyints). In my
program, I have assigned an enumeration to make the meaning clear, such as:

enum Condition {

Green = 0,
Yellow,
Red
}

In my database, one of the tables contains a "Condition" field (tinyint),
which stores the number 0, 1 or 2. However, in my Stored Procedures I am
having to use magic numbers as follows:

SELECT * From Nodes Where Condition = 1

(to select all nodes with yellow condition)

Obviously, meaning is obfuscated here. I would rather use constants but not
have to re-define them in every stored procedure I use.

I there any way to do this?

Jul 20 '05 #1
1 5947
You could create a UDF

create function uf_Condition( Status as varchar(6)) as integer
set uf_condition = case Status when 'Green' then 0
when 'Yellow' then 1
when 'Red' then 2
end

then
SELECT * From Nodes Where Condition = uf_Condition('Green')
On Wed, 3 Dec 2003 17:54:41 -0000, "Robin Tucker"
<id*************************@reallyidont.com> wrote:
I have several instances of "magic number" variables (tinyints). In my
program, I have assigned an enumeration to make the meaning clear, such as:

enum Condition {

Green = 0,
Yellow,
Red
}

In my database, one of the tables contains a "Condition" field (tinyint),
which stores the number 0, 1 or 2. However, in my Stored Procedures I am
having to use magic numbers as follows:

SELECT * From Nodes Where Condition = 1

(to select all nodes with yellow condition)

Obviously, meaning is obfuscated here. I would rather use constants but not
have to re-define them in every stored procedure I use.

I there any way to do this?


Jul 20 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: M Wells | last post by:
Hi All, I'm wondering if anyone can tell me if it's possible to search for stored procedures by their contents? I tend to leave very descriptive notes in stored procedures and they're...
11
by: jrefactors | last post by:
I want to know the differences between SQL Server 2000 stored procedures and oracle stored procedures? Do they have different syntax? The concept should be the same that the stored procedures...
2
by: scott | last post by:
Hi, Just wondering what sort of problems and advantages people have found using stored procedures. I have an app developed in VB6 & VB.NET and our developers are starting to re-write some of the...
2
by: Kent Lewandowski | last post by:
hi all, Recently I wrote some stored procedures using java jdbc code (admittedly my first stab) and then tried to implement the same within java packages (for code reuse). I encountered...
5
by: Tim Marshall | last post by:
I was following the thread "Re: Access Treeview - Is it Safe Yet?" with interest and on reading the post describing Lauren Quantrell's SmartTree, I've run into something I don't understand: Stored...
45
by: John | last post by:
Hi When developing vb.bet winform apps bound to sql server datasource, is it preferable to use SELECTs or stored procedure to read and write data from/to SQL Server? Why? Thanks Regards
28
by: mooreit | last post by:
The purpose for my questions is accessing these technologies from applications. I develop both applications and databases. Working with Microsoft C#.NET and Microsoft SQL Server 2000 Production and...
3
by: leesquare | last post by:
Hello, I need some help getting output values from my stored procedures when using adodbapi. There's an example testVariableReturningStoredProcedure in adodbapitest.py, and that works for my...
3
by: SLauren | last post by:
Hi, Can i declare some global constants in mysql, so that it can be used by all the stored procedures?? Thanks in advance, Lauren
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.