How do I use current user ID or name in SQL WHERE clause?
Last Post 10-19-2009 02:40 PM by Chad Nash. 6 Replies.
AddThis - Bookmarking and Sharing Button
Author Messages
Dick MallardUser is Offline
Posts:4
Avatar

--
09-24-2009 01:19 PM

    I have a simple SQL query that returns a value in Host/SQL but none when I use a Token in Tailored Text SQL. How is this intended to work? I cannot find an actual example in the docs for Tailored Text, the example uses a query string.

    Token for is $(CompanyName)

    Token Key
    SELECT Contacts.[CompanyName]

    FROM {objectQualifier}xxxxx_ContactDetail As Contacts
    WHERE Contacts.[UserName] = $(UserName)

    I've tried variations on the token as variable syntax such as [UserName], '$(UserName)'
    Also tried to match on UserID

     

    Dick MallardUser is Offline
    Posts:4
    Avatar

    --
    09-24-2009 01:34 PM

    This is with Tailored HTML v 2.10.21 on DNN 5.1.1

    David ToUser is Offline
    river guide
    river guide
    Posts:2719
    Avatar

    --
    09-24-2009 01:39 PM
    Try using the token $(UserID). -- David
    Dick MallardUser is Offline
    Posts:4
    Avatar

    --
    09-24-2009 02:03 PM

    David thanks for your response...

    I tried $(UserID) in my query and it did not work...

    But

    SELECT Username
    FROM {objectQualifier}Users
    WHERE UserID = $(UserID)

    works fine.

    The example query in my original post does not show I have to use 3 tables to get user's Company Name to display from UserID

    table1 CompanyDetails contains Company Name, CompanyID
    table2 ContactDetails contains Username, CompanyID
    table3 Users contains Username, UserID

    Is there some limit to the query that can be used? 
    I've read suggestions from Chad to use SProcs for this but don't know how. Is there an example for using stored procedures in the module's SQL token key?

    David ToUser is Offline
    river guide
    river guide
    Posts:2719
    Avatar

    --
    09-28-2009 07:13 AM
    Hi, try this SQL statement:

    select CompanyDetails.[Company Name] as defaultvalue from CompanyDetails inner join ContactDetails on CompanyDetails.CompanyID = ContactDetails.CompanyID inner join {objectQualifier}Users on ContactDetails.Username = {objectQualifier}Users.Username where {objectQualifier}Users.UserID = '$(UserID)'

    -- see if this works for you. -- David
    Dick MallardUser is Offline
    Posts:4
    Avatar

    --
    10-09-2009 12:04 PM

    David,

    Your suggestion did not work but showed me some things that when tweaked gave me the result I was looking for.

    Here is what finally worked:
    select {objectQualifier}CompanyDetail.[CompanyName] as Company from {objectQualifier}CompanyDetail inner join {objectQualifier}ContactDetail on {objectQualifier}CompanyDetail.[CompanyID] = {objectQualifier}ContactDetail.[CompanyID] inner join {objectQualifier}Users on {objectQualifier}ContactDetail.[Username] = {objectQualifier}Users.Username where {objectQualifier}Users.UserID = '$(UserID)'

    Possibly not the most concise, but I've got what I need!!!

    Thanks again

    Chad NashUser is Offline
    Posts:5260
    Avatar

    --
    10-19-2009 02:40 PM
    Dick,

    Thanks for posting the update, I am sure it will be helpful for other users!

    -Chad


    ---
  • film izle
  • 720 izle
  • film
  • sinema izle
  • film makinesi
  • T�rk�e dublaj film
  • film izle
  • film izle
  • baglan film izle
  • sinema izle
  • 1080 film izle
  • film mercegi