Skill 1.3 Implement functions and aggregate data Flashcards
What is the output of a ‘TRY_XXX’ conversion function when conversion fails?
NULL
What does the function GETDATE do?
Returns the current date and time in the SQL instance you are querying
What is the SQL standard equivalent of GETDATE?
CURRENT_TIMESTAMP
What is the difference between GETDATE and SYSDATETIME?
SYSDATETIME returns a DATETIME2 value instead of a DATETIME value
How are DATETIME and DATETIME2 values different?
DATETIME2 values have an accuracy of 100ns, DATETIME values are Rounded to increments of .000, .003, or .007 seconds
What is the output of the SYSDATETIMEOFFSET function?
SYSDATETIMEOFFSET returns a DATETIMEOFFSET value, which is a DATETIME2 date value plus the offset in hours from UTC
How do you get the date or time in T-SQL?
Cast the DATETIME, DATETIME2, or DATETIMEOFFSET value as DATE or TIME: CAST(GETDATE() as DATE), CAST(SYSDATETIME() as TIME)
What do the GETUTCDATE and SYSUTCDATETIME functions do?
The GETUTCDATE and SYSUTCDATETIME functions return DATETIME and DATETIME2 values converted to UTC time
What do you use the DATEPART function for?
The DATEPART function is used to extract part of a date (year, month, day, hour, minute, nanosecond) as an integer
What does the DATENAME function do?
DATENAME returns a character string that represents the specified datepart of the specified date
What functions does SQL provide for constructing DATETIME values from parts?
DATEFROMPARTS DATETIME2FROMPARTS DATETIMEFROMPARTS DATETIMEOFFSETFROMPARTS SMALLDATETIMEFROMPARTS TIMEFROMPARTS
What function gets you the end of month date for the given date and time value?
EOMONTH (It supports a second argument indicating how many months to add to the result)
What is the DATEADD function used for?
DATEADD takes a date, number of units, and a date part, and gives you a second date with that number of units of that part added. Negative units allows for subtraction.
What does the DATEDIFF function do?
DATEDIFF gives you the difference in units between two dates, expressed as an integer. Use DATEDIFF_BIG, if the difference doesn’t fit in a 4-byte integer.
What does SWITCHOFFSET do?
SWITCHOFFSET returns an input DATETIMEOFFSET value adjusted to a requested target offset. You can use it to convert a datetime in the one timezone to a datetime in another timezone
How is TODATETIMEOFFSET different from SWITCHOFFSET?
TODATETIMEOFFSET accepts a DATETIME value (not a DATETIMEOFFSET value) as input. You can use it to convert a datetime in the server’s current timezone into a datetime in another timezone
How is the function AT TIME ZONE different from SWITCHOFFSET?
AT TIME ZONE expects a time zone name (‘Pacific Standard Time’) instead of an offset value (‘-07:00’)
What two methods of concatenating strings does SQL Server support?
the plus (+) operator and the CONCAT function