Can the Pivot operator be used with text columns?
-
I am new to the Pivot operator in SQL Server. I see that the Pivot operator requires an aggregate function in order to work. However, I need to pivot a text column, and I can't find any examples that show how to do it. Am I barking up the wrong tree, or is there a way to pivot a text column?
The difficult we do right away... ...the impossible takes slightly longer.
-
I am new to the Pivot operator in SQL Server. I see that the Pivot operator requires an aggregate function in order to work. However, I need to pivot a text column, and I can't find any examples that show how to do it. Am I barking up the wrong tree, or is there a way to pivot a text column?
The difficult we do right away... ...the impossible takes slightly longer.
There are a few aggregate operators the work on
varchar
columns - for example,Max
. sql - PIVOT with varchar datatype - Stack Overflow[^] sql server - Pivot Table with varchar values - Stack Overflow[^] SQL Server pivoting on non-numeric data types - SQL Shack[^]
"These people looked deep within my soul and assigned me a number based on the order in which I joined." - Homer
-
I am new to the Pivot operator in SQL Server. I see that the Pivot operator requires an aggregate function in order to work. However, I need to pivot a text column, and I can't find any examples that show how to do it. Am I barking up the wrong tree, or is there a way to pivot a text column?
The difficult we do right away... ...the impossible takes slightly longer.
As long as you never have more than one value per row and column it doesn't matter very much which function you use as long as it works with text. (Min, Max or user defined). But depending on your data it might be possible to get more than one value per cell, then you need to choose what to show. That's what the aggregate function is for.
Wrong is evil and must be defeated. - Jeff Ello
-
There are a few aggregate operators the work on
varchar
columns - for example,Max
. sql - PIVOT with varchar datatype - Stack Overflow[^] sql server - Pivot Table with varchar values - Stack Overflow[^] SQL Server pivoting on non-numeric data types - SQL Shack[^]
"These people looked deep within my soul and assigned me a number based on the order in which I joined." - Homer
Thank you, Richard.
The difficult we do right away... ...the impossible takes slightly longer.
-
As long as you never have more than one value per row and column it doesn't matter very much which function you use as long as it works with text. (Min, Max or user defined). But depending on your data it might be possible to get more than one value per cell, then you need to choose what to show. That's what the aggregate function is for.
Wrong is evil and must be defeated. - Jeff Ello
Thank you Jörgen.
The difficult we do right away... ...the impossible takes slightly longer.