SQL Server Forums
Profile | Register | Active Topics | Members | Search | Forum FAQ
 
Register Now and get your question answered!
Username:
Password:
Save Password
Forgot your Password?

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 xml value method
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

basicconfiguration
Constraint Violating Yak Guru

356 Posts

Posted - 09/14/2012 :  14:47:54  Show Profile  Reply with Quote
How do i get the result:

Rose
Cosma
Alex
Sunny
Louis
White


select profileProperty.value,
profileProperty.value.value('(//string/@value)[1]', 'VARCHAR(15)')
from @profileProperty profileProperty





declare @profileProperty table(UserID int, PropertyID int, Value xml)


insert @profileProperty (userid, PropertyID, Value)
select 3, 2, '<string>Rose</string>' union all
select 3, 3, '<string>Cosma</string>' union all
select 1, 2, '<string>Alex</string>' union all
select 1, 3, '<string>Sunny</string>' union all
select 2, 2, '<string>Louis</string>' union all
select 2, 3, '<string>White</string>'

visakh16
Very Important crosS Applying yaK Herder

India
52317 Posts

Posted - 09/14/2012 :  14:52:28  Show Profile  Reply with Quote

declare @profileProperty table(userid int, PropertyID int, Value xml)
insert @profileProperty (userid, PropertyID, Value)
select 3, 2, '<string>Rose</string>' union all
select 3, 3, '<string>Cosma</string>' union all
select 1, 2, '<string>Alex</string>' union all
select 1, 3, '<string>Sunny</string>' union all
select 2, 2, '<string>Louis</string>' union all
select 2, 3, '<string>White</string>'


select Value.query('data(.)')
from @profileproperty


output
-------------------------------------
Rose
Cosma
Alex
Sunny
Louis
White



------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page

basicconfiguration
Constraint Violating Yak Guru

356 Posts

Posted - 09/14/2012 :  15:18:27  Show Profile  Reply with Quote
thankx V
Go to Top of Page

basicconfiguration
Constraint Violating Yak Guru

356 Posts

Posted - 09/14/2012 :  15:34:44  Show Profile  Reply with Quote
Now any ideas how to concatenate first and last name


declare @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 @users
select 1 union all
select 2 union all
select 3

insert @profileProperty (userid, PropertyID, Value)
select 3, 2, '<string>Rose</string>' union all
select 3, 3, '<string>Cosma</string>' union all
select 1, 2, '<string>Alex</string>' union all
select 1, 3, '<string>Sunny</string>' union all
select 2, 2, '<string>Louis</string>' union all
select 2, 3, '<string>White</string>'


result:
Rose Cosma
Alex Sunny
Louis White
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

India
52317 Posts

Posted - 09/14/2012 :  15:54:24  Show Profile  Reply with Quote
how would i know which is first and last name?

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page

basicconfiguration
Constraint Violating Yak Guru

356 Posts

Posted - 09/14/2012 :  16:51:32  Show Profile  Reply with Quote
propertyid 2 = fname ; propertyid3 = lastname

result:
Rose Cosma
Alex Sunny
Louis White
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

India
52317 Posts

Posted - 09/14/2012 :  17:09:16  Show Profile  Reply with Quote

declare @profileProperty table(userid int, PropertyID int, Value xml)
insert @profileProperty (userid, PropertyID, Value)
select 3, 2, '<string>Rose</string>' union all
select 3, 3, '<string>Cosma</string>' union all
select 1, 2, '<string>Alex</string>' union all
select 1, 3, '<string>Sunny</string>' union all
select 2, 2, '<string>Louis</string>' union all
select 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 LastName
from @profileproperty
group by userid


output
--------------------------------------------------------
userid	FirstName	LastName
1	Alex	        Sunny
2	Louis	        White
3	Rose	        Cosma



------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page

basicconfiguration
Constraint Violating Yak Guru

356 Posts

Posted - 09/27/2012 :  20:01:43  Show Profile  Reply with Quote
Thanks@!
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

India
52317 Posts

Posted - 09/27/2012 :  22:52:00  Show Profile  Reply with Quote
welcome

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page
  Previous Topic Topic Next Topic  
 New Topic  Reply to Topic
 Printer Friendly
Jump To:
SQL Server Forums © 2000-2009 SQLTeam Publishing, LLC Go To Top Of Page
This page was generated in 0.11 seconds. Powered By: Snitz Forums 2000