Required SQL statements (7) string functions, time functions, and SQL statements
String Functions
1. case-insensitive Conversion
-- Convert upper to uppercase
-- Lower to lowercase
Select upper ('asar ')
2. Length
-- Len words
-- Datalength bytes
3. Remove leading and trailing Spaces
-- Remove spaces on the Right of rtrim
-- Ltrim remove left space
4. String Truncation
-- Left ('string', 15) truncates 15 bytes from the Left
-- Right ('string', 15) truncates 15 bytes from the right
-- SubString ('string', 5, 5) captures 5 bytes starting from the left-side 5th bytes
5. String replacement
-- Replace ('you', 'you', 'I') to replace you with us
Time Functions
1. Get the current date
-- Getdate ()
2.100 days later
-- Dateadd (day, 100, getdate ())
3. Time Difference Function
-- Dateiff (year, '2014/1/11', getdate ())
4. query year, month, and day
-- Year (time) Get year
-- Month (time) Get month
-- Get day (time)
----------------
-- Calculate the number of people born in each year
Select year (birthday), count (*)
From table
Group by year ([birthday])
5. Obtain the year, month, day, hour, minute, and second of the date.
Datepart (year, date)
Datepart (month, date)
Datepart (day, date)
Datepart (hour, date)
Datepart (minute, date)
Datepart (second, date)