Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 1106907
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T01:51:39+00:00 2026-05-17T01:51:39+00:00

I have a table that contain about 60 columns and if i write a

  • 0

I have a table that contain about 60 columns and if i write a select query in query analyser to get a row it show it and i must scroll to show data ..
How can i get one row in which it shows as 60 row, each row contain 2 columns one for column name and other for value
For example Select * from table where id = 1 in default it shown as

ID Col1  Col2  Col3 Col4 Col5 ...... Col60  
1  v1    v2    v3   v4   v5   ...... v60

I want it to be shown as

ID    1  
Col1  v1  
Col2  v2  
Col3  v3
...  
Col60 v60
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-17T01:51:40+00:00Added an answer on May 17, 2026 at 1:51 am

    The below Stored Procedure do What you need

    CREATE PROCEDURE [dbo].[Rotat]
        -- Add the parameters for the stored procedure here
         @Where nvarchar(max),
         @tableName nvarchar(max)
    AS
    BEGIN
    
    Declare @SqlQuery nvarchar(max),@ColumnName nvarchar(255)
    DECLARE @TempTable TABLE 
    ( 
          ID int IDENTITY(1,1) , 
          ColumnName nvarchar(255), 
          ColumnValue ntext 
    )
    
    
    INSERT INTO @TempTable (ColumnName)
        SELECT      column_name
        FROM information_schema.columns
        WHERE table_name = @tableName 
    
    Declare @index int
    Set @index = 1;  
    
    Declare @Count int
    Select @Count = Count(ID) from @TempTable
    declare @columnValue  nvarchar(255)
    declare @paraDef nvarchar(max)
    declare @string nvarchar(max)
    
    WHILE @index <= @Count 
    BEGIN
        Select @ColumnName = ColumnName from @TempTable where id = @index
        set @string ='select @ret= cast('+ @ColumnName + ' AS nvarchar(255) )  
            from '+@tableName+' WHERE ' + @Where
    
        set  @paraDef=N'@ret nvarchar(255) output'
    
        EXECUTE sp_executesql @string, @paraDef,@ret=@ColumnValue  output
    
        UPDATE  @TempTable 
        SET     ColumnValue = @columnValue
        WHERE   ID =@index
    
        Set @index = @index + 1
    END
    
    Select * from @TempTable
    
    END
    

    Just call it an pass table name and your condition that will return one row for example

    EXEC    [dbo].[Rotat]
            @Where = 'UserID = 123456',
            @tableName = 'Users'
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a table that contains a few columns and one of them is
So, I have a mysql table that looks roughly like this, where the first
I have a table containing a large number of rows. Each row has 2
I have a table containing a large number of rows. Each row has 2
Let's say I have two tables: Table 1 has the columns NOTE_ID (a unique
I have currently created a facebook like page that pulls notifications from different tables,
I have a Java application with server and Swing client. Now I need to
I have a db related to horse racing performance and want to compare a
I have added Full Text Search to my sql server 2008 express database and

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.