Querying mp_userproperties table

If you have questions about using mojoPortal, you can post them here.

You may want to first review our site administration documentation to see if your question is answered there.

This thread is closed to new posts. You must sign in to post in the forums.
8/25/2011 5:20:00 PM
Gravatar
Total Posts 38

Querying mp_userproperties table

Hi,

I have created customized user profile fields.  I would like to retrieve the data as a single row per user.  

I thought perhaps a pivot would work to convert a result set like this:

Userid                          PropertyName       PropertyValueString

admin@admin.com         Address1              1060 West Addison

admin@admin.com         Zipcode                60613

user@user.com              Address1              257 E10th St

user@user.com              Zipcode                10002

 

To a table like this

 

Userid                          Address1                      Zipcode

admin@admin.com         1060 West Addison        60613

user@user.com              257 E10th St                 10002

 

 

Is there a standard method for achieving this?

 

Thanks,

 

Ken

8/26/2011 8:37:35 AM
Gravatar
Total Posts 38

Re: Querying mp_userproperties table

I see I can't get anyone to do my work for me.  Here's the syntax I worked out, pls let me know if there's an easier way to do it.  This will return a result set with a single row per user showing all requested field values and named custom properties.  The pivot requires an aggregate, hence "Max".  Seems to work.

Declare @Site int

Set @Site = 1
;With userData as (
select u.email,u.Gender,u.ProfileApproved,u.Country,u.State,u.Occupation,u.Interests,u.Signature,u.DateCreated
,p.PropertyName,p.PropertyValueString
from mp_users u
inner join mp_UserProperties p on u.UserGuid = p.UserGuid
Where SiteID = @Site
)

select * from userData o
PIVOT (MAX(PropertyValueString) for PropertyName in (Address1,Address2,County,[Home Tel],[Home Fax],[Home Email])) p

You must sign in to post in the forums. This thread is closed to new posts.