We help IT Professionals succeed at work.
Get Started

SQL Server: Write a query with dynamic column names

493 Views
Last Modified: 2012-05-12
I am writing a select query using opendatasource to get data from an excel file.
There are 100s of columns in the file and i want to select only columns whose name starts with "MR"
e.g. if there are columns MR1, MR4, MR5, GG1, something5

The select query will return only MR1, MR4 and MR5

Note: The number of columns in the excel file is not constant and the count of columns starting with MR may change because of which i cannot hardcode these names.

Need help on this urgently as i am stuck.

Thanks in advance
Comment
Watch Question
Senior Developer
CERTIFIED EXPERT
Commented:
This problem has been solved!
Unlock 1 Answer and 4 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