Help with SELECT

Discussion in 'Databases' started by ChaosTrivia, Mar 17, 2009.

  1. #1
    Hello! Somebody knows the solution to my problem?

    I have two tables in my users database:
    Table 1:
    UserName, UserID, LastActivityDate
    Table 2:
    UserID, EmailAddress

    I want to select EmailAddress and UserName for all users whose LastActivityDate is more than 21 days ago { where DateDiff(day, LastActivityDate, getdate())>21 }
    My SQL server is MSSQL 2005.
    Thanks in advance!
     
    ChaosTrivia, Mar 17, 2009 IP
  2. ChaosTrivia

    ChaosTrivia Active Member

    Messages:
    2,093
    Likes Received:
    40
    Best Answers:
    0
    Trophy Points:
    65
    #2
    Hmmm...... I managed to do it with somekind of "View" that I found on the server. but It would be nice if someone of you guys knows how to construct a SELECT statement that could do the job.
     
    ChaosTrivia, Mar 17, 2009 IP
  3. anhbloginc

    anhbloginc Well-Known Member

    Messages:
    1,288
    Likes Received:
    15
    Best Answers:
    0
    Trophy Points:
    175
    #3
    You can use it with CREATE A VIEW OR PROC !
    If need exactly code , reply at here i will post again help you
     
    anhbloginc, Mar 17, 2009 IP
  4. anhbloginc

    anhbloginc Well-Known Member

    Messages:
    1,288
    Likes Received:
    15
    Best Answers:
    0
    Trophy Points:
    175
    #4
    With view

    Then you can select * from [view_name] that's mean "select * from ChaosTrivia"
    It will show you result you want
     
    anhbloginc, Mar 17, 2009 IP
  5. nirajkum

    nirajkum Active Member

    Messages:
    815
    Likes Received:
    5
    Best Answers:
    0
    Trophy Points:
    58
    #5
    why do we need to have few we can use join and fetch the data. Correct me if I am wrong
     
    nirajkum, Mar 18, 2009 IP
  6. XandroZ

    XandroZ Peon

    Messages:
    395
    Likes Received:
    4
    Best Answers:
    0
    Trophy Points:
    0
    #6
    SELECT table1.username, table2.emailadress FROM 
                table1 INNER JOIN table2 0N table1.userid=table2.userid where DateDiff(day, LastActivityDate, getdate())>21  
    Code (markup):
     
    XandroZ, Mar 18, 2009 IP