Search
 
SCRIPT & CODE EXAMPLE
 

SQL

sql column to row

DECLARE @colsUnpivot AS NVARCHAR(MAX),
   @query  AS NVARCHAR(MAX)

select @colsUnpivot 
  = stuff((select ','+quotename(C.column_name)
           from information_schema.columns as C
           where C.table_name = 'yourtable' and
                 C.column_name like 'Indicator%'
           for xml path('')), 1, 1, '')

set @query 
  = 'select id, entityId,
        indicatorname,
        indicatorvalue
     from yourtable
     unpivot
     (
        indicatorvalue
        for indicatorname in ('+ @colsunpivot +')
     ) u'

exec sp_executesql @query;
Comment

PREVIOUS NEXT
Code Example
Sql :: mysql not equal 
Sql :: oracle simple quote 
Sql :: sql delete duplicate 
Sql :: mysql case when in select 
Sql :: SQL column name Oracle 
Sql :: postgres extract time from timestamp 
Sql :: query to delete a database in mysql 
Sql :: Using GROUP BY in MySQL Join Table 
Sql :: union vs intersect sql 
Sql :: t-sql check if data exists 
Sql :: get table column names sql 
Sql :: sql add column with default value 
Sql :: sql values to array of objects 
Sql :: oracle enable chain 
Sql :: truncate table in sql 
Sql :: update multiple columns in sql 
Sql :: mysql workbench tutorial 
Sql :: mysql expression is not in group by clause 
Sql :: create a PostgreSQL user django on mac 
Sql :: sql rename column in select query 
Sql :: redo files log oracle 
Sql :: execut sql python 
Sql :: sql server: how to concatenate column data using comma 
Sql :: sql case statement 
Sql :: decimal() mysql 
Sql :: close external port 3306 with iptables 
Sql :: export database sql file from xampp using cmd 
Sql :: postgres get last value 
Sql :: what is denormalization in sql 
Sql :: drop database mysql 
ADD CONTENT
Topic
Content
Source link
Name
7+7 =