Steynsk
asked on
Problem with special characters in SQL Pivot string
Hi Expert,
I've got this table:
And this pivot query:
All works well until a name is containing a minus sign (-). Like in the example below:
Of Course I know that is not the way you should a name like that but I simplified and translated the problem.
How can I deal with this problem?
I've got this table:
CREATE TABLE membership(
[memberID] [int] NOT NULL,
[username] [nvarchar](50) NULL,
[groupname] [nvarchar](50) NULL
)
insert into membership (memberID,username,groupname) values(28,'Bill','Domain users')
insert into membership (memberID,username,groupname) values(30,'Bill','Application B')
insert into membership (memberID,username,groupname) values(33,'Judy','Domain users')
insert into membership (memberID,username,groupname) values(34,'Judy','Application A')
insert into membership (memberID,username,groupname) values(36,'John','Domain users')
insert into membership (memberID,username,groupname) values(37,'John','Application B')
insert into membership (memberID,username,groupname) values(38,'John','Printer 45')
And this pivot query:
SELECT * FROM (SELECT memberID, groupname, username FROM ADS_membership) t PIVOT (MIN(memberID) FOR username IN (Bill,Judy,John)) p
All works well until a name is containing a minus sign (-). Like in the example below:
SELECT * FROM (SELECT memberID, groupname, username FROM ADS_membership) t PIVOT (MIN(memberID) FOR username IN (Billy-Boy,Judy,John)) p
Of Course I know that is not the way you should a name like that but I simplified and translated the problem.
How can I deal with this problem?
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER