Chapter 4 QUERYING AND MODIFYING DATA 221 Where:
Chapter 4 QUERYING AND MODIFYING DATA 221 Where: date_part determines which unit of time measure needs to be found. The values it can take were shown in Table 4.7. date is an expression denoting the date being used. Here s an example of using DATENAME to find the name of the current month: Select datename(mm,getdate()) as month The DATEPART and DATENAME functions produce the specified part of a datetime value (the year, quarter, day, hour, and so on) as either an integer or a string. Because smalldatetime is accurate only to the minute, when a smalldatetime value is used with either of these functions, the seconds and milliseconds returned are zero. DATEPART DATEPART is similar to DATENAME except that it returns an integer value indicating the date rather than a character string. The syntax for DATEPART is the same as for DATENAME. The following is an example using DATEPART to find the current month and display it numerically: SELECT datepart(mm,getdate()) AS month Many useful date functions give the developer flexibility in dealing with what is traditionally one of the more pesky data types: Dates. With history reflecting unfavorably on the storage of date information, it is important to consider this data type to be infinite in that dates need to remain unique as time progresses. Numeric data types have always had useful functionality supplied with the programming environment in most languages. SQL Server is no exception with its adoption of a standard set of mathematical functions. Using Mathematical Functions in T-SQL A mathematical function performs a math operation on numeric expressions and returns the result of the operation. Math functions operate on any of the SQL Server numeric data types (decimal, integer, float, real, money, smallmoney, smallint, and
For high quality website hosting services please check cheap web hosting website.