We help IT Professionals succeed at work.
Get Started

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

Last Modified: 2017-11-30
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.  

Watch Question
SQL Server Data Dude
Most Valuable Expert 2013
Author of the Year 2015
This problem has been solved!
Unlock 1 Answer and 5 Comments.
See Answer
Why Experts Exchange?

Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.

Jim Murphy
Programmer at Smart IT Solutions

When asked, what has been your best career decision?

Deciding to stick with EE.

Mohamed Asif
Technical Department Head

Being involved with EE helped me to grow personally and professionally.

Carl Webster
CTP, Sr Infrastructure Consultant
Ask ANY Question

Connect with Certified Experts to gain insight and support on specific technology challenges including:

  • Troubleshooting
  • Research
  • Professional Opinions
Did You Know?

We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE