Results 1 to 7 of 7
  1. #1
    Join Date
    Apr 2010
    Posts
    9

    Question Unanswered: How to select columns name from the table with query?

    I've got the table1 with column names:
    Id,Name,Surname

    How I can select this columns with Query?

    Thank you

  2. #2
    Join Date
    Jan 2007
    Location
    UK
    Posts
    11,434
    Provided Answers: 10
    George
    Home | Blog

  3. #3
    Join Date
    Apr 2010
    Posts
    9
    thanks.
    is it possible to query the result horizontaly?

    I mean to select columns like:
    Id,Name,Surname


    SELECT column_name
    FROM information_schema.columns
    WHERE table_name = 'table11'

    Provide this info:
    Id,
    Name,
    Surname

  4. #4
    Join Date
    Dec 2007
    Location
    Richmond, VA
    Posts
    1,328
    Provided Answers: 5
    take a look at recursion

  5. #5
    Join Date
    Feb 2004
    Location
    One Flump in One Place
    Posts
    14,912
    Even better - tell us what your final goal is. What are you trying to achieve and why?

    I have a suspicion that if you write a recusive CTE it will not do what you want even though it will answer your question.

  6. #6
    Join Date
    Apr 2010
    Posts
    9
    I want to select cloumns nma elike a string.
    Thats all

  7. #7
    Join Date
    Feb 2004
    Location
    One Flump in One Place
    Posts
    14,912
    Code:
    DECLARE @sql    AS VARCHAR(MAX)
    
    SELECT  @sql    = COALESCE(@sql + ', ', '') + name 
    FROM    sys.all_columns
    WHERE   object_id   = OBJECT_ID('dbo.t_name')
    
    PRINT    @sql

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •