Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

stuck on SQL query, plz help

Status
Not open for further replies.

taval

Programmer
Jul 19, 2000
192
GB
----------------------<br>SELECT f.CustId, min(f.UploadDate)as FirstDate, max(fd.UploadDate)as LastDate from FileDescription f, FileDescription fd, Customer where f.CustId = fd.CustId and f.FileID = fd.FileID and not(DateDiff(day, f.UploadDate, getdate()) &gt; &quot;& numDays & &quot; ) Group by f.CustId Order By f.CustId<br>-----------------------<br><br>The above shows the details of customers that have backed up between a certain time period. I want to know the details of customers who have NOT backed up within the time period.<br><br>I was guessing one way to do this is to take all the customers that have been backed up away from all of the customers which should leave all the customers that haven't backed up???. How would I do this?<br><br>I've tried doing it without the not next to datediff but it doesn't give the correct results<br>Grateful for any help given.<br>Thanks.&nbsp;&nbsp;
 
Dear taval,<br><br>Based on your description would this work?<br><br>(DateDiff(day, f.UploadDate, getdate()) &lt; &quot;& numDays & &quot; ) <br><br>-pete
 
pete, I tried doing what you've said but that doesn't work either, thats why I think I try and do in my original post.<br>Do you know how I should setup me SQL query. I was thinking to do something like this as an example.<br><br>-----------------------------------<br>Select * from FileDescription<br>Minus<br>SELECT f.CustId, min(f.UploadDate)as FirstDate, max(fd.UploadDate)as LastDate from FileDescription f, FileDescription fd, Customer where f.CustId = fd.CustId and f.FileID = fd.FileID and not(DateDiff(day, f.UploadDate, getdate()) &gt; &quot;& numDays & &quot; ) Group by f.CustId Order By f.CustId<br>--------------------------------------<br><br>Note the above code is an idea of what I try and have to do, it does not work.<br><br>Thanks for trying to help anyway.<br><br>
 
Taval,<br>here's a query which works fine with test tables.<br>Of course, it needs to be modified to fit in your schema.&nbsp;&nbsp;<br><br>select uname,fileid,dtuploadmin,dtuploadmax from table1,table3 where table1.uid = table3.uid and DateDiff(day, dtUploadmax, getdate())&gt; somenumber<br>order by uname&nbsp;&nbsp;<br>
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top