Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

The detailed explanation could be found on Red Gate SimpleTalk's link 'An Easier Way of Transposing Query Result in SQL Server'https://www.red-gate.com/simple-talk/sql/t-sql-programming/easier-way-transposing-query-result-sql-server/

NotificationsYou must be signed in to change notification settings

Darko-Martinovic/TransposingMatrix

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

89 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

-EXEC MATRIX.TRANSPOSING @query = N'SELECT * FROM SYS.DATABASES';

✅ To save transposing query results in a temporary or permanent table.

+The table will be created inside the stored procedure, and after that, you have to drop the table manually.+There is no need to create a temporary or a permanent table first.+The whole task is accomplished inside the stored procedure.+The account that executes stored procedure has to have "CREATE TABLE permission."
-EXEC MATRIX.TRANSPOSING  @query = N'SELECT * FROM sys.databases', @tableName = N'##tempTable';
+---The same result as in the first query
-SELECT * FROM ##tempTable;

✅ To choose transposing column

+--The first column - the database name
-EXEC MATRIX.Transposing @Query = N'SELECT * FROM sys.databases' ,@Rco = 0;
+--The second column - the database ID
-EXEC MATRIX.Transposing @Query = N'SELECT * FROM sys.databases',@Rco = 1;

✅ To filter before transposing

-EXEC MATRIX.Transposing @Query = N'SELECT * FROM sys.databases WHERE database_id >= @id1 AND database_id <= @id2;',-                        @Params = N'@id1 int=1,@Id2 int=4';

✅ To transpose with generic header ( key, value, value1 and so on )

-EXEC MATRIX.Transposing @Query = N'SELECT * FROM sys.databases;',@KeyValueOption = 1;

✅ To transpose with custom header

-EXEC MATRIX.Transposing @Query = N'SELECT * FROM sys.databases;'-  ,@KeyValueOption = 1-  ,@ColumnMapping = N'Database name,Sys database master'

About

The detailed explanation could be found on Red Gate SimpleTalk's link 'An Easier Way of Transposing Query Result in SQL Server'https://www.red-gate.com/simple-talk/sql/t-sql-programming/easier-way-transposing-query-result-sql-server/

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

[8]ページ先頭

©2009-2025 Movatter.jp