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

  • SEARCH
  • Home
  • 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 7584393
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T18:54:35+00:00 2026-05-30T18:54:35+00:00

I have this query DECLARE @Test TABLE ( RowID INT IDENTITY(1,1) PRIMARY KEY ,[Name]VARCHAR(10)

  • 0

I have this query

DECLARE @Test TABLE
(
     RowID  INT IDENTITY(1,1) PRIMARY KEY
    ,[Name]VARCHAR(10) NOT NULL
    ,tool   VARCHAR(10) NOT NULL,
    stam NVARCHAR(MAX)

);  
INSERT  @Test   VALUES ('john', 'vocals','1');
INSERT  @Test   VALUES ('john', 'guitar','1');
INSERT  @Test   VALUES ('paul', 'vocals','1');
INSERT  @Test   VALUES ('paul', 'bass','1');
INSERT  @Test   VALUES ('george', 'vocals','1');
INSERT  @Test   VALUES ('george', 1,'1');
INSERT  @Test   VALUES ('ringo', 'vocals','1');
INSERT  @Test   VALUES ('ringo', 3,'1');
INSERT  @Test   VALUES ('ringo', 'drums','1');
INSERT  @Test   VALUES ('yoko', 'vocals','1');
INSERT  @Test   VALUES ('royi', 'vocals','1');
INSERT  @Test   VALUES ('royi', 'guitar','1');


;WITH PivotSource
AS
(
    SELECT   t.[Name], t.[tool]  
     FROM    @Test t
)

SELECT  * 
FROM    PivotSource  
 PIVOT   ( max(tool) FOR tool IN ([vocals], [guitar], [bass],[drums]) ) pvt;

the result is :

enter image description here

is there any way to replace null with "" ( empty string) ? ( without modifying the CTE data !)

  • 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-30T18:54:36+00:00Added an answer on May 30, 2026 at 6:54 pm

    Use:

    SELECT pvt.Name
        , isnull(pvt.[vocals], '') [vocals]
        , isnull(pvt.[guitar], '') [guitar]
        , isnull(pvt.[bass], '') [bass]
        , isnull(pvt.[drums], '') [drums]
    FROM PivotSource  
    PIVOT
    (
        max(tool) 
        FOR tool 
        IN ([vocals], [guitar], [bass], [drums]) 
    ) pvt;
    

    Output:

    Name       vocals     guitar     bass       drums
    ---------- ---------- ---------- ---------- ----------
    george     vocals                           
    john       vocals     guitar                
    paul       vocals                bass       
    ringo      vocals                           drums
    royi       vocals     guitar                
    yoko       vocals                           
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to execute this query: declare @tablename varchar(50) set @tablename = 'test'
I have problem with this query DECLARE @INPUT INT SET @INPUT = 12345 ;
I have this table variable declaration followed by a query: DECLARE @CurrentItems TABLE (
Let's say I have this SQL query: declare @input varchar(20) select * from myTable
I have this SQL query (in T-SQL): --DECLARE @strTerm varchar(300) --SET @strTerm = 'c'
I have built a T-SQL query like this: DECLARE @search nvarchar(1000) = 'FORMSOF(INFLECTIONAL,hills) AND
I have this query working but it is not returning back exactly what I
I have this SQL Server query: DECLARE @HoursUsed float SELECT COLUMN_A ,(SELECT (@HoursUsed =
I have this query in SQL Server 2005: SELECT J.JobID, dbo.tblCustomers.Name AS CustomerName, J.CustomerJobNumber,
I have the following query: Declare @cnt as int Declare @int as int Set

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.