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 wOOdy-Soft on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Number of Days Query

Status
Not open for further replies.

Lack

IS-IT--Management
Jan 18, 2005
45
US
Ok, I'm somewhat of a rookie....can anyone tell me the expression I would use for finding out the number of days between to dates? For instance, I have a CLOSE_DATE column and a DESIRED_WANT_DATE column in a table that are stricly date/time stamps. I want to be able to take [CLOSE_DATE]-[DESIRED_WANT_DATE] and have the query return the number of days difference but it keeps returning and odd 1900 date in the result. I seem to be able to get this working in Access. Am I missing something on the SQLServer side? Any help would be appreciated. Thx!
 
try....

Select DateDiff(Day, [close_date], [DESIRED_WANT_DATE])


-George

Strong and bitter words indicate a weak cause. - Fortune cookie wisdom
 
Thanks George for your quick reply. Yes, I just had to add the FROM statement and it worked. what is your recommendation on me learning this stuff? Is there a good book out there? Class is the only way? I would appreciate any ideas. I am somewhat familiar with MS Access, but new to the SQLServer and it's Reporting Services. Thanks a ton George!
 
Now if I could just figure out how to get it into Reporting Services...:)
 
There are plenty of good books, but I haven't read them.
The last programming class I took was Fortran-77 back in my college days (think early 90's).

I can't answer you regarding the best way to learn this stuff because it depends on your personality. Some prefer classes, others prefer books. Me... I prefer tek-tips! I've learned more about SQL programming here than anywhere else (which is probably the number 1 reason why I help others).

Click on the FAQ's button at the top of this page. There is a FAQ's devoted to SQL Books.

In my opinion, it is more important to know 'what is available' than it is to know how to use it. For example, I'm sure you didn't know about DateDiff function. Likewise, there are probably many other functions that you are also unaware of.

If you are using Query Analyzer to build your queries, then do this...

1. Make sure the 'object browser' is visible. If you don't see it, then press F8 on your keyboard.
2. Scroll down to 'common objects'.
3. Expand each branch to see a list of functions that are available to you.
4. Read through the list. It's not important that you know how each function works. What's important is that you know what functions are available.

I hope this helps.

-George

Strong and bitter words indicate a weak cause. - Fortune cookie wisdom
 
Awesome advice from a pro..thanks George. I have the Object Browser visible, but am unable to find the "common objects" you are referring too. FYI..we are running SQLServer 2005 version 9.00.2047.00.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top