0

I'm new to SQL Server programming, so this may or may not be a stupid question.

So, first I do not know what my input table is (my task is supposed to work with ANY table).

Second, I get the column names using sp_help and then I select only that column into another table. Now I need the rows from COLUMN_NAME to be the names of god knows how many columns into some new table.

I tried something using PIVOT, but I can't seem to make it work.

2
  • HI Ivonne, welcome to stackoverflow. Can you please post the queries that you have already tried? That way we can have a better understanding of what you are trying to achieve or where the error might be.
    – JanR
    Jun 25, 2013 at 0:37
  • The thing is, I can't make anything to work, since I don't know the values of the rows that are supposed to be my names of the columns, so none of the codes I've tried makes any sense, and it would not change anything if I post them here. :/
    – Ivonne
    Jun 25, 2013 at 15:58

1 Answer 1

0

It sounds like you want to access the metadata tables. Something like this may put you in the right direction:

insert into column_name(name)
    select column_name
    from information_schema.columns
    where table_name = XXX       <----- YOUR TABLE GOES HERE
1
  • Can't use this, cause I don't know the names of the column, cause my code is supposed to work with any table.
    – Ivonne
    Jun 25, 2013 at 16:01

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.