Please start any new threads on our new
site at https://forums.sqlteam.com. We've got lots of great SQL Server
experts to answer whatever question you can come up with.
Author |
Topic |
basicconfiguration
Constraint Violating Yak Guru
358 Posts |
Posted - 2012-09-14 : 14:47:54
|
How do i get the result:RoseCosmaAlexSunnyLouisWhiteselect profileProperty.value,profileProperty.value.value('(//string/@value)[1]', 'VARCHAR(15)') from @profileProperty profilePropertydeclare @profileProperty table(UserID int, PropertyID int, Value xml)insert @profileProperty (userid, PropertyID, Value)select 3, 2, '<string>Rose</string>' union allselect 3, 3, '<string>Cosma</string>' union allselect 1, 2, '<string>Alex</string>' union allselect 1, 3, '<string>Sunny</string>' union allselect 2, 2, '<string>Louis</string>' union allselect 2, 3, '<string>White</string>' |
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2012-09-14 : 14:52:28
|
[code]declare @profileProperty table(userid int, PropertyID int, Value xml)insert @profileProperty (userid, PropertyID, Value)select 3, 2, '<string>Rose</string>' union allselect 3, 3, '<string>Cosma</string>' union allselect 1, 2, '<string>Alex</string>' union allselect 1, 3, '<string>Sunny</string>' union allselect 2, 2, '<string>Louis</string>' union allselect 2, 3, '<string>White</string>'select Value.query('data(.)')from @profilepropertyoutput-------------------------------------RoseCosmaAlexSunnyLouisWhite[/code]------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/ |
 |
|
basicconfiguration
Constraint Violating Yak Guru
358 Posts |
Posted - 2012-09-14 : 15:18:27
|
thankx V |
 |
|
basicconfiguration
Constraint Violating Yak Guru
358 Posts |
Posted - 2012-09-14 : 15:34:44
|
Now any ideas how to concatenate first and last namedeclare @users table (UserID int)declare @profileProperty table(UserID int, PropertyID int, Value xml)declare @entityList table (EntityName varchar(50), EntityID int, Name varchar(50))insert @usersselect 1 union allselect 2 union allselect 3insert @profileProperty (userid, PropertyID, Value)select 3, 2, '<string>Rose</string>' union allselect 3, 3, '<string>Cosma</string>' union allselect 1, 2, '<string>Alex</string>' union allselect 1, 3, '<string>Sunny</string>' union allselect 2, 2, '<string>Louis</string>' union allselect 2, 3, '<string>White</string>'result:Rose CosmaAlex SunnyLouis White |
 |
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2012-09-14 : 15:54:24
|
how would i know which is first and last name?------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/ |
 |
|
basicconfiguration
Constraint Violating Yak Guru
358 Posts |
Posted - 2012-09-14 : 16:51:32
|
propertyid 2 = fname ; propertyid3 = lastnameresult:Rose CosmaAlex SunnyLouis White |
 |
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2012-09-14 : 17:09:16
|
[code]declare @profileProperty table(userid int, PropertyID int, Value xml)insert @profileProperty (userid, PropertyID, Value)select 3, 2, '<string>Rose</string>' union allselect 3, 3, '<string>Cosma</string>' union allselect 1, 2, '<string>Alex</string>' union allselect 1, 3, '<string>Sunny</string>' union allselect 2, 2, '<string>Louis</string>' union allselect 2, 3, '<string>White</string>'select userid,max(case when PropertyID = 2 THEN CAST(Value.query('data(.)') as varchar(100)) end) as FirstName,max(case when PropertyID = 3 THEN CAST(Value.query('data(.)') as varchar(100)) end) as LastNamefrom @profilepropertygroup by useridoutput--------------------------------------------------------userid FirstName LastName1 Alex Sunny2 Louis White3 Rose Cosma[/code]------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/ |
 |
|
basicconfiguration
Constraint Violating Yak Guru
358 Posts |
Posted - 2012-09-27 : 20:01:43
|
Thanks@! |
 |
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2012-09-27 : 22:52:00
|
welcome------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/ |
 |
|
|
|
|
|
|