Discover datediff function in sql, include the articles, news, trends, analysis and practical advice about datediff function in sql on alibabacloud.com
Tags: t-SQL ProgrammingHere, we introduce the functions of T-SQL, such as mathematical functions, string functions, conversion functions, date functions, and custom functions.1. Mathematical Functions:
Name of function
function action
Abs
Calculate absolute Value
1
Tags: sqlSQL Advanced (7) Date function SQL dates when we work on dates, the hardest task is to make sure that the date is inserted in a format that matches the format of the date column in the database.As long as the data contains only the date parts, running the query will not be a problem. However, if time is involved, the situation is a little more complicated.Before we discuss the complexity of the dat
Alter function fuc (@userid int, @strWhere varchar (max), @strWhere2 varchar (max)) returns decimal (18,2)AsBeginDECLARE @useridlist varchar (max) = ", @res decimal (18,2) = 0;With CTE as(Select id,1 Layer from T_user where id=64UNION ALLSelect A.id,layer=layer+1 from CTE Inner joins t_user A on a.uplineid=cte.id and CTE. Layer) Select @[email protected]+ ', ' +cast (ID as varchar ()) from the CTE where CTE. LayerDECLARE @UserGradeDateLine varchar (ma
Label:getdate () function Returns the current date and time of the system in the default format of datetime Syntax format: getdate () Year () Month () Day () function Returns the year, month, and date value in Date_expression Syntax format: year/month/day (date_expression datetime/varchar) Returns int Example: Year (GETDATE ()), year (' 2016-05-01 ') datename () funct
,datalengthO:length www.knowsky.com28. Capitalization Conversion Lower,upper
29. Capitalize the first letter of the wordS: I didn't find it.O:select initcap (' ABCD Dsaf df ') value from dual
30. Left fill space (the first parameter of Lpad is a space function)S:select space + ' ABCD ' valueO:select lpad (' ABCD ') value from dual
31. Right complement space (the first parameter of Rpad is a space function)S
SQL Date Data typeSQL Server uses the following data types to store date or date/time values in the database:
DATE-Format YYYY-MM-DD
DATETIME-format: Yyyy-mm-dd HH:MM:SS
smalldatetime-format: Yyyy-mm-dd HH:MM:SS
TIMESTAMP-Format: Unique number
Use the following SELECT statement:SELECT GETDATE () as CurrentdatetimeThe DATEPART () function is used to return a separate part of a date/
string in a stringSelect STUFF (' asdf ', 2,0, ' DF ')--Play spaceSelect SPACE (4)--The first occurrence of an index number in a stringSelect CHARINDEX (' A ', ' Dsaf ')--Take the string to the leftSelect Left (' Qwert ', 3)--Right Fetch stringSelect Right (' Qwert ', 3)--Turn capitalSelect UPPER (' ASD ')--Turn lowercaseSelect LOWER (' ASD ') --Date function[Email protected] @DATEFIRST The first day of the week, DW is the @@ 系统 constantSELECT @ @DAT
Paip. program function time performance optimization and SQL statement Optimization
Author attilax,1466519819@qq.com
Tracking Tool xdebug ..1
Profiler log analysis tool wincachegrind.2
Obtain the complete SQL statement from the code for testing...2
Test SQL statement time...2
Disable
, ' DF ')--Play spaceSelect SPACE (4)--The first occurrence of an index number in a stringSelect CHARINDEX (' A ', ' Dsaf ')--Take the string to the leftSelect Left (' Qwert ', 3)--Right Fetch stringSelect Right (' Qwert ', 3)--Turn capitalSelect UPPER (' ASD ')--Turn lowercaseSelect LOWER (' ASD ')--Date function[Email protected] @DATEFIRST The first day of the week, DW is the @@ 系统 constantSELECT @ @DATEFIRST as ' 1st day ', DATEPART (DW, GETDATE ()
SQL Server String FunctionsString functions are used to perform various operations on characters and binary characters1.ASCII () functionThe ASCII (character_expression) function is used to return the leftmost ASCII code value in a string expression. The parameter character_expression must be a string expression of char or varchar type. Eg:select ASCII (' s '), ASCII ('
Label:get one months of days: first to the date of the last day of the one month, by using the SQL Server Date function day () to get the "days" part of the date Number of days to get February 2008:Select Day (CAST (' 2008-03-01 ' as DateTime)-1) Get the number of days this month: Returns an integer that indicates which day of the month the specified date is. Select Day (DateAdd (Month,1,getdate ()) – Day (
SQL Server table-valued function and scalar-valued function define the way and call difference
SQL stored procedures often need to call some functions to make the process more reasonable, you can also make functions more reusable, but when writing SQL functions you may find
First, the basic concept:
SQL functions can contain any number of queries, but the function only returns the result of the last query (which must be a select). In simple cases, returns the first row of the last query result. If the last query does not return any rows, the function returns a null value. If you need this funct
, nvarchar, char, varchar, nchar, or nvarchar data types), or string format styles, whereby float, Real, money, or smallmoney data is converted to character data (nchar, nvarchar, char, varchar, nchar, or nvarchar data types). Output when converted to character data.
Implicit conversions are not visible to users.SQL Server automatically converts data from one data type to another data type. For example, if a smallint variable is compared to an int variable, the smallint variable is implicitly c
PL/SQL program block Declarations section, this is more obvious is the subroutine, the subroutine can be in the execution part of the reference, can also be referenced in the Exception handling section. PL/SQL blocks can be compiled independently and stored in a database, and any application connected to the database can access these stored PL/SQL blocks. OR
Oracle 11g PL/SQL function result cache, oracle11g
Two experiments have been conducted to simulate the Oracle Performance Diagnosis art. The book says that if you don't need RELIES_ON, then the changes to the objects on which the function depends will not result in the invalid result cache operation (result_cache RELIES_ON (test1, test2). The test proves that thi
This article illustrates the function and usage of SQL Server to implement Split function split string. Share to everyone for your reference, specific as follows:
/*
function Name: F_splittonvarchar function
: To realize the functio
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.