Here's what the StoredProc which grabs all of the users with the custom properties I want looks like.
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[Custom_UserProfiles_SelectAll]
/*
Last Modified: 2011-11-27
*/
@SiteID int
AS
CREATE TABLE #usersWithProperties
(
SiteID int,
UserID int,
UserGuid uniqueidentifier,
FirstName nVarChar(Max),
LastName nVarChar(Max),
Email nVarChar(Max),
Gender nVarChar(1),
Supervisor nVarChar(Max),
SupervisorID int,
JobTitle nVarChar(Max),
Organization nVarChar(Max),
MobilePhone nVarChar(Max),
WorkPhone nVarChar(Max),
Photo nVarChar(Max),
Birthdate nVarChar(Max)
)
INSERT INTO #usersWithProperties (SiteID, UserID, UserGuid, FirstName, LastName, Email, Photo, Gender)
SELECT SiteID, UserID, UserGuid, FirstName, LastName, Email, AvatarUrl, Gender
FROM mp_Users
WHERE SiteID = @SiteID
AND mp_Users.DisplayInMemberList = 'True'
UPDATE #usersWithProperties
SET Supervisor = (
SELECT u.Name FROM mp_Users u
WHERE u.UserID = (
SELECT uP.PropertyValueString FROM mp_UserProperties uP
WHERE uP.PropertyName = 'Supervisor'
AND #usersWithProperties.UserGuid = uP.UserGuid
)
)
,SupervisorID = (
SELECT uP.PropertyValueString FROM mp_UserProperties uP
WHERE uP.PropertyName = 'Supervisor'
AND #usersWithProperties.UserGuid = uP.UserGuid
)
,Organization = (
SELECT REPLACE(r.DisplayName, 'org_', '') FROM mp_Roles r
WHERE r.RoleID = (
SELECT uP.PropertyValueString FROM mp_UserProperties uP
WHERE uP.PropertyName = 'Organization'
AND #usersWithProperties.UserGuid = uP.UserGuid
)
)
,JobTitle = (
SELECT PropertyValueString FROM mp_UserProperties uP
WHERE uP.PropertyName = 'JobTitle'
AND #usersWithProperties.UserGuid = uP.UserGuid
)
,MobilePhone = (
SELECT PropertyValueString FROM mp_UserProperties uP
WHERE uP.PropertyName = 'MobilePhone'
AND #usersWithProperties.UserGuid = uP.UserGuid
)
,WorkPhone = (
SELECT PropertyValueString FROM mp_UserProperties uP
WHERE uP.PropertyName = 'WorkPhone'
AND #usersWithProperties.UserGuid = uP.UserGuid
)
,Birthdate = (
SELECT PropertyValueString FROM mp_UserProperties uP
WHERE uP.PropertyName = 'Birthdate'
AND #usersWithProperties.UserGuid = uP.UserGuid
)
SELECT * FROM #usersWithProperties
DROP TABLE #usersWithProperties
We had a lot of other fields but this should get you started.