Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Adding Columns in SQL

Status
Not open for further replies.

TSO456

Technical User
Jul 23, 2001
57
US
I have a table that shows account numbers


Account Numbers
3000
4000
4500
5000


I would like to use SQL to add a column called Flag to the table and flag accounts with a word character when the account number is within a particular range.

For example if the account number is between 3000 and 4000 add the word LOW to the column adjacent to the account column and put LOW next to 3000 and 4000 account numbers.


Account Number Flag
3000 LOW
4000 LOW
4500
5000

I appreciate your help
 
CREATE VIEW aTableWithFlag AS
SELECT AccountNumber,
(CASE
WHEN AccountNumber BETWEEN 3000 AND 4000 THEN "LOW"
ELSE ""
END) AS "Flag"
FROM aTableOfAccountNumbers
 
I like the solution provided by <rac2>.

But re-reading your post, I was wondering if what you were asking for was:
(a) some 'Alter Table' script to permanently add the new column to the table, and
(b) an 'Update' script to populate the new column with the correct values.

That wasn't it, was it?
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top