Tags: des style blog http color ar data Art divLearn from:http://bjtdeyx.iteye.com/blog/1447300The most common statements for SQL date queries -- query data on the first anniversary of the date of the day select * from shoporder where datediff (Week,ordtime,getdate () - 1 ) = 0 -- query all data for the day Select * from where DateDiff (Day, Ordtime,getdate()-1) = 0 --info is the table name, DateTime is the field value in the database--On
To get the day of the week, you need to use the DATE function in SQL Server: Datename ().Today is the day of the week, Example 1: Set Language N ' 中文版 ' select Datename (Weekday, GETDATE ()) WednesdayToday is the day of the week, Example 2: Set Language N ' Simplified Chinese ' select Datename (Weekday, GETDATE ()) WednesdayToday is the day of the week, example 3: Set Datefirst 1select datepart (W
Obtain two random records FROM table A and use select top 10 * FROM ywle order by newid ()Order by is generally sorted by a certain field. The return value of newid () is uniqueidentifier. How does order by newid () randomly select records?Newid () generates a value when scanning each record, and the generated value is random, with no case sequence. so the final result is sorted by this sort, and the sorting result is of course unordered.OrSelect top 10 *, newid () as Random from ywle where ywle
isT_to_order_ticketsWheret_to_order_tickets.order_id = Oi. order_idAndto_char (departure_time, 'yyyymmdd') =To_char (sysdate, 'yyyymmdd '))There was a problem here. departure_time was originally indexed, but the index was not used here, because the to_char method could not make it index again,This is the key to the problem. This problem can be solved through function indexing.
SQL> Create index test2011021
, @ FirstName, @ LastName, @ JobTitle, @ ContactType;
End;
Return;
End;
Function:
Select * from dbo. ufnGetContactInformation (1 );
Iv. deterministic and non-deterministic Functions
1. deterministic Functions
For the same set of input values, the same value is returned every time a deterministic function is called.
2. Non-deterministic Functions
Different results may be returned each time a non-deterministi
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 dateNumber 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 (GetDate ()
Label: Turn from http://jimshu.blog.51cto.com/3171847/1376637/ The open window function is defined in the ISO standard. SQL Server provides ranking window functions and aggregate windowing functions. Before the window function appears, there are many problems that can be solved by SQL statements, many of which are do
Php function code for SQL injection and escape. SQL injection: Normally: delete. php? Deletefromnewswhereid. $ _ GET [id]; malicious situation: delete. php? Deletefromnewswhereid3or1; --- SQL injection:
Under normal circumstances:
Delete. php? Id = 3;$ SQL = 'delete from ne
Only SQL functions can be used in a SELECT statement to manipulate fields (linked SQL Server).Select field 1 from Table 1 where field 1. IndexOf ("cloud") = 1;The reason this statement is not correct is that the indexof () function is not a SQL function, and it can be change
Label:This is when we open the bin-log and we have to specify whether our function is1 Deterministic indeterminate2 No SQL does not have SQL statements and of course does not modify the data3 READS SQL Data just reads and of course does not modify the data4 modifies SQL data
Tags: from shu display Alt ACL class development used todayRecently done in the project, accidentally found in the SQL statement appeared as the word, has not been much attention to what meaning, after all, the impact is not big, today is free, on-line search some information, probably have some understanding Our SQL statements are common in many databases, such as the MySQL database Access database. Oracle
Scenario: When we create a new table in the DW, but there is no model created in FM, and want to do a report directly for this table, then we need to query directly with SQL in Reportstudio, in order to pursue the query speed, we can pass the conditions of the page user selection directly to SQL.For example: above is the province corresponding key value is 1-2-3-4-5, the following is the product type corresponding key value is 1-2, the province select
Example 1
The code is as follows
Create function F_split (@SourceSql varchar (8000), @StrSeprate varchar)
returns @temp table (a varchar (100))
--function of the split function
--date:2003-10-14
as
begin
Declare @i int
set @SourceSql =rtrim LTrim (@ Sourcesql))
set @i=charindex (@StrSeprate, @SourceSql) while
@i>=1
begin
Insert @temp VALUES ( Left (@Sou
function | function/*
T-sql:17 a date-time related Custom function (UDF), Sunday as the last day of the week, not affected by the @ @DateFirst, language version
are collected or refined from the old articles!
Tips:
(@ @Datefirst + datepart (weekday, @Date))% 7 judgment Week is the most insured! Independent of @ @DateFi
from dbo. GETGrade2 (' Zhang San ',' language ')Create a stored procedure, find a stored procedureCREATE PROC p_view (@userName nvarchar (ten), @subject nvarchar ( e-mail Protected] and [subject]=@subjectENDExecute the storage process' John Doe ',' mathematics 'Essentially no difference. Just a function like: Only one variable can be returned with a limit. A stored procedure can return more than one. Functions can be embedded in
Common date functions
SQL Server time and date function detailed, SQL Server, time, date,
1. Current system date, time
Select GETDATE ()
2. DateAdd returns a new datetime value on the basis of adding a period of time to the specified date
For example: Add 2 days to date
Select DATEADD (day,2, ' 2004-10-15 ')--back: 2004-10-17 00:00:00.000
3. DateDiff retur
This article illustrates the method of Php+mysql to realize the function of multiple-keyword and multi-field generating SQL statements. Share to everyone for your reference. The implementation methods are as follows:
First look at the example:
Copy Code code as follows:
$keyword = "1 2 3";
echo $sql =search ($keyword, "Enter_gongyin_pic", "a+b+c"
The format () function is used to format the display of a field.
SQL FORMAT () syntax
SELECT FORMAT (Column_name,format) from table_name;
Parameters
Description
column_name
Necessary. The field to format.
Format
Necessary. Specified format.
Demo Database
In this tutorial, we will use the well-known Northwind sample database.
Here
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.