SQL statement

Results 1 to 3 of 3

Thread: SQL statement

  1. #1
    K. Guest

    Default SQL statement

    I have a database that has a large number of records of tickets assigned to agents. The agents are captured in the database by using Request.ServerVariables("LOGON_USER").<BR>With database changes that were made I have a situation where one user could be<BR>BIRMGTEjdoe (with the domain) or jdoe (without the domain). When agents are logged in, they click on a page to view their tickets. I want to be able to pull records for the agents based on NT username (who they are logged in as) and capture both formats. I tried to use:<BR>SQL = "Select * FROM tblAssignedEscalations WHERE EGA Like &#039%" & Request.ServerVariables("LOGON_USER") & "&#039 ORDER BY Date" <BR>using a wildcard for the beginning characters because the end part of the user will always be the same, with or without the domain. How can I accomplish this since what I tried didn&#039t do the trick?

  2. #2
    Steve Cimino Guest

    Default RE: SQL statement

    Why isn&#039t it working? The statement looks ok to me. Make sure you have data in that server variable that matches the db.<BR><BR>If you&#039re still having problems, you can use an OR statement:<BR><BR>SELECT * FROM tablename<BR>WHERE EGA = &#039jdoe&#039 OR EGA = &#039BIRMGTEjdoe&#039

  3. #3
    Join Date
    Dec 1969

    Default RE: SQL statement

    Hopefully I understand your situation. It sounds like your logic is slightly flawed. With your scenario, if I am logged in as "BIRMGTEjdoe" and the database record has me as "jdoe", you will not get a match. What you need to do, I think, is check for both instances. First, get the ServerVariable into a string variable, then create a second variable that only has the username:<BR><BR>&#060;%<BR>str1 = Request.ServerVariables("LOGON_USER")<BR>If InStr(str1, "\") Then<BR> str2 = Right(str1, Len(str1) - InStr(str1, "\"))<BR>Else<BR> str2 = "bogus text that could never match" &#039not the most elegant, but what the hey<BR>End If<BR>SQL = "SELECT * FROM tblAssignedEscalations WHERE EGA LIKE &#039%" & str1 & "&#039 OR EGA LIKE &#039%" & str2 & "&#039 ORDER BY Date"<BR>%&#062;<BR><BR>This way, if I am logged in as "BIRMGTEjdoe" I will match "BIRMGTEjdoe" or "jdoe". If I am logged in as "jdoe", the wildcard will kick in and I will match again. Hope this does the trick.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts