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

 
Developer Updates  
Free Website Content 
IBM Developerworks
 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: 5 stars5 stars5 stars5 stars5 stars / 3
    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:
      Del.ici.ous Digg
      Blink Simpy
      Google Spurl
      Y! MyWeb 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

    Route your faxes to your email inbox. Private, secure fax numbers available from CallWave. Choose your fax number.

    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...


    DISCLAIMER: The content provided in this article is not warranted or guaranteed by Developer Shed, Inc. The content provided is intended for entertainment and/or educational purposes in order to introduce to the reader key ideas, concepts, and/or product reviews. As such it is incumbent upon the reader to employ real-world tactics for security and implementation of best practices. We are not liable for any negative consequences that may result from implementing any information covered in our articles or tutorials. If this is a hardware review, it is not recommended to open and/or modify your hardware.

     

       

    BRAINDUMP ARTICLES

    - Outsourcing: the Hoopla, the Reality
    - MySQL Plays in the Sun
    - All About SQL Functions
    - SQL: Functioning in the Real World
    - More Advanced SQL Statements
    - Beginning SQL the SEQUEL: Working with Advan...
    - Beginning SQL
    - A Look at the VI Editor
    - A Quick Tour of Boo
    - Book Review: Open Source Licensing
    - PGP and GPG: Email for the Practical Parano...
    - Microsoft Continues War on Open Source
    - Secure Remote Desktop Sharing with VNC on Li...
    - A Look at Google Project Hosting
    - What we can Learn from Two Linux vs. Microso...

     
    Accelerating Trading Partner Performance
     
    Competing on Analytics
     
    Cost Effective Scaling with Virtualization and Coyote Point Systems
     
    Five Checkpoints to Implementing IP Telephony
     
    Hosted Email Security: Staying Ahead of New Threats
     




    © 2003-2008 by Developer Shed. All rights reserved. DS Cluster 2 hosted by Hostway