MS SQL Server shorthand (function or something) to refer to specific columns

Hey there,

I'm working with a table that has about 200 columns (seems like I am ALWAYS doing that).  
I'd like to do something quick that would allow me to refer to columns in "groups" and have my select return just the columns that pertain to that group.  

For instance, if I wanted to write a select statement that brought back all of the possible address related fields from my table, instead of saying:
SELECT Address1Street, Address1City, Address1State, Address1ZIP, Address2Street, Address2City, Address2Zip, Address3Street etc etc.
I would just say something like
SELECT @AddressFields FROM MyTable and it would grab all the address related fields.  

I'm thinking like a lookup table of fields and groups and an SP or something?  

No big deal - I probably just spent more time thinking about it and writing this question than it's worth.  Just wondering if anyone had a cool trick they've used to make that easier.  

Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Do the columns all have similar names, ie Address%,  Stuff%, etc...?
Jim HornSQL Server Data DudeCommented:
You could create a View that contains the subset of columns in the way you are referring to as 'Groups', then just call the view.

CREATE VIEW MyTable_Address AS

SELECT Name, Address1, Address2, City, [State], Zip
FROM YourTable

Open in new window

... then to select them...
SELECT * FROM MyTable_Address

Open in new window

You can also use a Stored Procedure, and maybe even pass as a parameter an ID value, like this..
CREATE PROC MyTable_Address (@id int) AS

SELECT Name, Address1, Address2, City, [State], Zip
FROM YourTable
WHERE id = @id OR @id IS NULL

Open in new window

... then to select them...
exec MyTable_Address 42

Open in new window

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
ste5anSenior DeveloperCommented:
Well, it's called normalization ;) but I guess it's a data warehouse table..

There is not such short hand other than Jim's solution.
ttist25Author Commented:
AGX - no - unfortunately in this table the field names are all things like ASDF and GHJKL.  :)

And yes, st5an, normalization - hah!  :P

Jim the view idea will be perfect for what I'm trying to do.  Thanks!
@ttist25 - Okay, then Jim's idea is the way to go.
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.