Avatar of ttist25
ttist25
 asked on

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.  

Thanks!
Microsoft SQL ServerSQL

Avatar of undefined
Last Comment
_agx_

8/22/2022 - Mon
_agx_

Do the columns all have similar names, ie Address%,  Stuff%, etc...?
ASKER CERTIFIED SOLUTION
Jim Horn

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
GET A PERSONALIZED SOLUTION
Ask your own question & get feedback from real experts
Find out why thousands trust the EE community with their toughest problems.
ste5an

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.
ttist25

ASKER
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!
Your help has saved me hundreds of hours of internet surfing.
fblack61
_agx_

@ttist25 - Okay, then Jim's idea is the way to go.