This is the SQL script that calculates the first day of the one month:SELECT DATEADD (mm, DATEDIFF (Mm,0,getdate ()), 0)--the first day of the monthSELECT DATEADD (mm, DATEDIFF (Mm,0,getdate ())-1, 0)-the first day of the monthSELECT DATEADD
Insert
How to get an ID automatically generated after the last time you insert a record
Author: Amoy Net
Source: Amoy Net
NOTE: Reprint please indicate the source
If you use stored procedures, it will be very simple, the code is as follows: SET
onTo say there is an article table article, the time to store an article's added article is the Add_time field, which is an int (5) type, you now need to query the total number of articles added today and sort by time from large to small, then the
SQL statements remove duplicate records, get duplicate records
--Query a table to effectively remove duplicate records, UserID as a self-growing primary key, Roleid as a repeating field
The code is as follows
Copy Code
A recent problem in the development project was to get the ID in the database immediately after inserting a record, and that ID was self increasing. There are several ways in which SQL Server 2005 can be implemented. The easiest way to get this ID
DECLARE@dtdatetimeSET@dt=GETDATE()DECLARE@numberintSET@number=3--1. Specify a date the first or last day of the year--A. The first day of the yearSelectconvert (Char(5),@dt, -)+'1-1'--B. The last day of the yearSelectconvert (Char(5),@dt, -)+'12-31'-
MS SQL Server Query optimization methodThere are many reasons for the slow speed of queries, which are common1, no indexes, or no indexes (this is the most common problem with query slowness, is the flaw in programming)2, I/o throughput is small,
Select @ identity usage 11:25:39| Category: JSP Dev|Report|Font SizeSubscription Use select @ identity to obtain the ID automatically generated when the last record is inserted. If you use a stored procedure, the Code is as follows: Set @ [email
How to obtain the ID automatically generated after the last insert recordAuthor: Tao InternetSource: TaotaoNote: Please indicate the source for reprinting.If you use a stored procedure, the code is as follows: SET @ NewID = @ IDENTITYNote:After an
sql--aggregate function (Aggregate functions): Avg,count,first,last,max,min,sumavg () functionDefinition and UsageThe AVG function returns the average of a numeric column. NULL values are not included in the calculation.SQL AVG () syntaxSELECT AVG
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.