Products

Solutions

Resources

Partners

Community

Blog

About

QA

Ideas Test

New Community Website

Ordinarily, you'd be at the right spot, but we've recently launched a brand new community website... For the community, by the community.

Yay... Take Me to the Community!

Welcome to the DNN Community Forums, your preferred source of online community support for all things related to DNN.
In order to participate you must be a registered DNNizen

HomeHomeUsing DNN Platf...Using DNN Platf...Administration ...Administration ...SQL query users and addresses help neededSQL query users and addresses help needed
Previous
 
Next
New Post
12/11/2008 8:29 AM
 

Hi all

I hope I can get some help to make a query for users on my dnn4.9 site.

I would like to get an extract like

Username
Displayname,
Firstname
Lastname
Street
City
Zipcode
email
Phonenumber

I'm no wizard in SQL and I got completly stuck in the properties and the join relations there.

Can anybody assist here?

Thanks
Henry

 
New Post
12/11/2008 11:34 AM
 

 

This is a general query that will give you what you are looking for. This query pulls usernames from ALL portals.

SELECT Users.Username, Users.FirstName, Users.LastName, Users.DisplayName, Users.Email, UserProfile.PropertyValue AS Street,
UserProfile_1.PropertyValue AS City, UserProfile_2.PropertyValue AS ZipCode, UserProfile_3.PropertyValue AS Telephone
FROM Users INNER JOIN
UserProfile ON Users.UserID = UserProfile.UserID INNER JOIN
UserProfile AS UserProfile_1 ON Users.UserID = UserProfile_1.UserID INNER JOIN
UserProfile AS UserProfile_2 ON Users.UserID = UserProfile_2.UserID INNER JOIN
UserProfile AS UserProfile_3 ON Users.UserID = UserProfile_3.UserID
WHERE (UserProfile.PropertyDefinitionID = 26) AND (UserProfile_1.PropertyDefinitionID = 27) AND (UserProfile_2.PropertyDefinitionID = 30) AND
(UserProfile_3.PropertyDefinitionID = 31)

 

Beware - the 'PropertyDefinitionID's may be unique to my installation. Execute the query below to see if yours are different.
substitute the correct PropertyDefinitionIDs in the above query if necessary.

SELECT DISTINCT PortalID, PropertyDefinitionID, PropertyName
FROM ProfilePropertyDefinition
WHERE (PortalID = 0)
ORDER BY PropertyDefinitionID

 

If you want to pull usernames from a specific portal, use this query and change the portal ID.

SELECT Users.Username, Users.FirstName, Users.LastName, Users.DisplayName, Users.Email, UserProfile.PropertyValue AS Street,
UserProfile_1.PropertyValue AS City, UserProfile_2.PropertyValue AS ZipCode, UserProfile_3.PropertyValue AS Telephone
FROM Users INNER JOIN
UserProfile ON Users.UserID = UserProfile.UserID INNER JOIN
UserProfile AS UserProfile_1 ON Users.UserID = UserProfile_1.UserID INNER JOIN
UserProfile AS UserProfile_2 ON Users.UserID = UserProfile_2.UserID INNER JOIN
UserProfile AS UserProfile_3 ON Users.UserID = UserProfile_3.UserID INNER JOIN
UserPortals ON Users.UserID = UserPortals.UserId
WHERE (UserProfile.PropertyDefinitionID = 26) AND (UserProfile_1.PropertyDefinitionID = 27) AND (UserProfile_2.PropertyDefinitionID = 30) AND
(UserProfile_3.PropertyDefinitionID = 31) AND (UserPortals.PortalId = 0)

 
New Post
12/11/2008 12:08 PM
 

Henry-
You didn't mention anything about user roles / security groups.  Do you really want this info for every account on your portal?  For example, you may want to exclude users in the ADMINISTRATOR role or exclude users who never logged in except for the day the account was created (i.e., users who created an account but never returned).

DNN Object Classes
It's often much easier to get this kind of info via the exposed attributes of appropriate DNN code objects than to write your own queries.  The DNN framework has already done all the hard work in linking together the appropriate DB tables to bring you those consolidated code objects.

Since you've specifically asked for a query I'll assume you're either creating a report external to DNN or are using a "SQL module" to report the results within your DNN site.  If you're not familiar with "SQL modules", there are a couple of good free ones I've used a lot and have blogged about here:

  Advanced DataGrid (Part 1):  http://www.eguanasolutions.com/DNN_Blog/EntryID/2.aspx

  Advanced DataGrid (Part 2):  http://www.eguanasolutions.com/DNN_Blog/EntryID/5.aspx
  Advanced DataGrid (Part 3):  http://www.eguanasolutions.com/DNN_Blog/EntryID/13.aspx
  SQLView:  http://www.eguanasolutions.com/DNN_Blog/EntryID/15.aspx

If, however, you are using the query in order to populate something in code then you'd likely do better to check into the object classes provided by DNN. Here's a potentially helpful link:  http://www.howtodotnetnuke.com/tabid/120/smid/481/ArticleID/7/t/Getting-Aquainted-with-the-DNN-Classes/Tutorials.aspx


SQL Query 
All that said, here's one stab at the query you asked for.  This is a standalone query and does not leverage existing DNN SPs or functions.  I added a column for "PortalId" in case you have more than one portal and I sorted the results by portal-lastname-firstname.  Please note that this is an inefficient way to retrieve this info but I thought the arrangement would help illustrate relationships between the USER and USER PROFILE-related tables:

  declare @pid int;
  set @pid = (Your portal's ID value here);  -- Use '0' if you haven't created multiple portals 
  SELECT
    upo.PortalId, u.Username, u.DisplayName, u.FirstName, u.LastName, u.Email,
    (select upr1.PropertyValue from UserProfile upr1
      INNER JOIN ProfilePropertyDefinition ppd1 on
      ppd1.PropertyDefinitionId = upr1.PropertyDefinitionId
     where
      (ppd1.portalid = @pid) and (PropertyCategory = 'Address')
       and (PropertyName = 'Street') and (upr1.userid = u.userid)
     ) as [Street],
    (select upr1.PropertyValue from UserProfile upr1 
      INNER JOIN ProfilePropertyDefinition ppd1 on 
      ppd1.PropertyDefinitionId = upr1.PropertyDefinitionId
     where
      (ppd1.portalid = @pid) and (PropertyCategory = 'Address')
       and (PropertyName = 'City') and (upr1.userid = u.userid)
     ) as [City],
    (select upr1.PropertyValue from UserProfile upr1 
      INNER JOIN ProfilePropertyDefinition ppd1 on 
      ppd1.PropertyDefinitionId = upr1.PropertyDefinitionId
     where
      (ppd1.portalid = @pid) and (PropertyCategory = 'Address')
       and (PropertyName = 'PostalCode') and (upr1.userid = u.userid)
     ) as [ZIP],
    (select upr1.PropertyValue from UserProfile upr1 
      INNER JOIN ProfilePropertyDefinition ppd1 on 
      ppd1.PropertyDefinitionId = upr1.PropertyDefinitionId
     where
      (ppd1.portalid = @pid) and (PropertyCategory = 'Contact Info')
       and (PropertyName = 'Telephone') and (upr1.userid = u.userid)
     ) as [Telephone]
   
   FROM USERS u INNER JOIN UserPortals upo on upo.UserId = u.UserId
   WHERE upo.portalid = @pid
   ORDER BY LastName, FirstName

 
Have fun-
-mamlin


esmamlin atxgeek.me
 
New Post
12/17/2008 5:13 AM
 

THANK YOU BOTH  I'm happy to get some replies.

I'm actually trying to populate a table called "map_points" from the dotnetnuke module "map" - since the build in "import" of users function doesn't work, for some reason the imported data does not represent the actual numbers of members on our site. The support for that module is close to "non existing" so I wanted to solve it by making a costum query to see if I could make it work that way.

I'm no DNN programmer, I have no web programming skills so I have to try solving this by "configuration" and/or SQL queries (where I'm also no wizard :s) feels a bit like a dead end :)

Anyway your queries does some of the job, that's a good start.

I need to, as you suggest, to select something where "inRole" = "Klubmedlem". Where should I put that in the query?

Thanks Again
Henry

 

 

 
New Post
1/5/2009 7:52 AM
 

Hi again mamlin

Do you think you could help me out on the inRole = "something"?

regards
Henry

 
Previous
 
Next
HomeHomeUsing DNN Platf...Using DNN Platf...Administration ...Administration ...SQL query users and addresses help neededSQL query users and addresses help needed


These Forums are dedicated to discussion of DNN Platform and Evoq Solutions.

For the benefit of the community and to protect the integrity of the ecosystem, please observe the following posting guidelines:

  1. No Advertising. This includes promotion of commercial and non-commercial products or services which are not directly related to DNN.
  2. No vendor trolling / poaching. If someone posts about a vendor issue, allow the vendor or other customers to respond. Any post that looks like trolling / poaching will be removed.
  3. Discussion or promotion of DNN Platform product releases under a different brand name are strictly prohibited.
  4. No Flaming or Trolling.
  5. No Profanity, Racism, or Prejudice.
  6. Site Moderators have the final word on approving / removing a thread or post or comment.
  7. English language posting only, please.
What is Liquid Content?
Find Out
What is Liquid Content?
Find Out
What is Liquid Content?
Find Out