Hello Greg,
You wrote in conference microsoft.public.access.adp.sqlserver on Wed, 16
Aug 2006 13:14:02 -0700:
GS> Greetings everyone. I need help with a stored procedure. I need to
GS> add a column to enter a value, either 1,2, or 3 depending on the value
GS> of another field in the query. For example, if the value of the
GS> independent field is 'apple' I need the new dependent field to populate
GS> '2'. I think I need to do a case when statement, but I can not get it
GS> to work. Is this anywhere close?
Generally, for the purpose like this the right approach is not hardcoding
the values, but creating a separate table Fruits:
fruit fruitId
apple 2
orange 3
and getting the value by lookup: select fruitId from fruits where
fruit='apple'
The advantage of this is that later, when you add new fruit, you do it by
adding new row to the Fruits table. Otherwise, you will have to find all
occurences of apples etc. in all places (in the database and in the
applications) where you hardcoded the values - and with the time, there will
be many.
Of course, it's kinda general guidance, for educational purposes. If it's
small one-time piece without the future, CASE is ok.
Vadim Rapp
|