BrainDump
  Home arrow BrainDump arrow Page 6 - All About SQL Functions
Dev Shed Forums  
Administration  
AJAX  
Apache  
BrainDump  
DHTML  
Flash  
Java  
JavaScript  
Multimedia  
MySQL  
Oracle  
Perl  
PHP  
Practices  
Python  
Reviews  
Security  
Smartphone Development  
Style-Sheets  
Web Services  
XML  
Zend  
Zope  
Mobile Linux  
App Generation ROI  
IBM® developerWorks  
Forums Sitemap  
E-Commerce Hosting  
Linux Web Hosting  
Managed Hosting  
Small Business Hosting  
VPS Hosting  
Weekly Newsletter

 
Developer Updates  
Free Website Content 
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Write For Us Get Paid  
Request Media Kit
Contact Us  
Site Map  
Privacy Policy  
Support  
 USERNAME
 
 PASSWORD
 
 
  >>> SIGN UP!  
  Lost Password? 
BRAINDUMP

All About SQL Functions
By: James Payne
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: starstarstarstarstar / 4
    2007-12-17


    Table of Contents:
  • All About SQL Functions
  • More Aggregate Functions
  • STDEV
  • Scalar Functions
  • Mid(c,start[,end]
  • Round(c,decimals)

  • Rate this Article: Poor Best 
      ADD THIS ARTICLE TO:
      error-file:tidyout.log Del.ici.ous error-file:tidyout.log Digg
      error-file:tidyout.log Blink error-file:tidyout.log Simpy
      error-file:tidyout.log Google error-file:tidyout.log Spurl
      error-file:tidyout.log Y! MyWeb error-file:tidyout.log Furl
    Email Me Similar Content When Posted
    Add Developer Shed Article Feed To Your Site
    Email Article To Friend
    Print Version Of Article
    PDF Version Of Article

     
     
    ADVERTISEMENT


    All About SQL Functions - Round(c,decimals)
    ( Page 6 of 6 )

    With the Round function you can round off a number to a specific number of decimal places. Here is an example:


    Select Round(1.75,1) as SampleColumn from Employees;

    This would result in the number 2, as we are rounding up 1 decimal. Had the numbers in the parentheses been (1.76,2), the function would have returned 1.8.

    Now()

    Now returns the current date and time based on your computer's system date and time. If these are not properly set, the result will be wrong.


    Select Now() As SampleColumn from Employees;

    This would return something like: 10/20/2007 8:32:19 PM. "A long, long time ago" is not an option.

    DateDiff(d,date1,date2)

    This function returns the difference between two dates. The syntax is like this:

      Select DateDiff('d',#10/10/2007#,Now()) as SampleColumn from Employees;

    This would return the difference between 10/10/2007 and today's date. There are a lot of options you can use with the DateDiff function, which I do not have the space to go over. However, I will say that you can use an alternate Syntax, which is:

      DateDiff ( interval, date1, date2[, firstdayofweek[, firstweekofyear]] )

    You can fool around with the Interval, firstdayofweek, and firstweekofyear sections by inserting data from the following tables:


    For the Interval Section

    What it does

    YYYY

    Year

    Q

    Quarter

    M

    Month

    Y

    Day of the Year

    W

    Weekday

    WW

    Week

    H

    Hour

    N

    Minute

    S

    Second

     

    For Firstdayofweek

    Value

    What it Does

    vbUseSystem

    0

    Uses the NLS API

    VbSunday

    1

    Sunday

    VbMonday

    2

    Monday

    VbTuesday

    3

    Tuesday

    etc




    For Firstweekofyear

    Value

    What it Does

    VbUseSystem

    0

    Uses the NLS API

    VbFirstJan1

    1

    First Week in January

    VbFirstFourDays

    2

    Starts with the first week of the year that has a minimum of four days

    VbFirstFullWeek

    3

    Starts with the first full week of the year

    Well that's it for this episode. I did leave out two of the more complex functions listed, but don't worry: I will be doing a future tutorial on even more functions in SQL, and I will cover those there. Hope you enjoyed.

    Till then...



     
     
    >>> More BrainDump Articles          >>> More By James Payne
     

       

    BRAINDUMP ARTICLES

    - Demystifying SELinux on Kernel 2.6
    - Yahoo and Microsoft Create Ad Partnership
    - The Advantages of Obscure Open Source Browse...
    - Dell Announces CSI-style Digital Forensics S...
    - Milepost GCC Speeds Open-Source Development
    - Learn These 10 Programming Languages
    - Tomcat Capacity Planning
    - Internal and External Performance Tuning wit...
    - Tomcat Benchmark Procedure
    - Benchmarking Tomcat Performance
    - Tomcat Performance Tuning
    - Wubi: Windows-based Ubuntu Installer
    - Configuring and Optimizing Your I/O Scheduler
    - Linux I/O Schedulers
    - Advising the Linux Kernel on File I/O





    © 2003-2009 by Developer Shed. All rights reserved. DS Cluster 2 Hosted by Hostway
    Stay green...Green IT