0

So I want to do a simple select like so:

select * from table

But this table has, for example, 100 columns. I'll only need the columns where "substring" is in the name, like say table has 3 columns: "firstPoints", "secondPoints", "thirdPoints", and then 97 columns without "Points" in the name, is there a way to do a select that only selects the columns that have the substring "Points" in it's name? Like:

select * like '%Points%' from table

Or something like that, so that, without explicitly passing the columns I want, I still get the select but only of those 3 columns that has "Points" in their name.

Tempuslight
  • 1,004
  • 2
  • 17
  • 34

1 Answers1

0

The Answer is like this:

  SELECT TOP 1000 COLUMN_NAME
  FROM {databasename}.INFORMATION_SCHEMA.COLUMNS
  WHERE TABLE_NAME = '{tablename}' and COLUMN_NAME like '%Datum%'

This will return a column "COLUMN_NAME" with records of my column names on that table containing "Datum" for example, in my example on my DB it returns 6 column names.

Tempuslight
  • 1,004
  • 2
  • 17
  • 34