TAILIEUCHUNG - Microsoft SQL Server 2008 R2 Unleashed- P173

Microsoft SQL Server 2008 R2 Unleashed- P173:SQL Server 2005 provided a number of significant new features and enhancements over what was available in SQL Server 2000. This is not too surprising considering there was a five-year gap between these major SQL Server 2008 is not as much of a quantum leap forward from SQL Server 2005 | 1664 CHAPTER 43 Transact-SQL Programming Guidelines Tips and Tricks convert the date value into a date you need. You need to start thinking in terms of date intervals for example how many date intervals it is from the current date to the date you want to calculate or how many date intervals it is from today to some other date such as 2000-01-01 and so on. You use the DATEADD and DATEDIFF functions to calculate your desired date by determining the appropriate date intervals from the current date and then adding or subtracting intervals to arrive at the desired calculated date. Understanding how to use the various date intervals helps you more easily understand how to calculate the desired dates. Calculating the First Day of Month Let s look at a method for determining the first day of the month for a given date. To do this you start out with the initial date. In this example you can use getdate to work with the current system date and time. The next step is to figure out the number of months between the given date and the date 1 1 1900 . NOTE The value 1 1 1900 is the default for a date if an empty string 11 is used to represent a date. You can use the DATEDIFF function to determine the number of months from 1 1 1900 select DATEDIFF mm getdate go 1321 Now using the number of months you can add that result to 1 1 1900 to obtain the first day of the month for the given date select DATEADD mm DATEDIFF mm getdate J By adding the number of months between the given date and 1 1 1900 to 1 1 1900 you are able to arrive at the first day of the current month. In addition the time portion of the calculated date is set to 00 00 . This technique for calculating a date interval between the current date and the year 1900-01-01 and then adding the calculated number of intervals to 1900-01-01 can be used to calculate many different dates. The next four examples use the same technique to generate different dates based on the current date. Calculating the First Day of the Year

TỪ KHÓA LIÊN QUAN
TAILIEUCHUNG - Chia sẻ tài liệu không giới hạn
Địa chỉ : 444 Hoang Hoa Tham, Hanoi, Viet Nam
Website : tailieuchung.com
Email : tailieuchung20@gmail.com
Tailieuchung.com là thư viện tài liệu trực tuyến, nơi chia sẽ trao đổi hàng triệu tài liệu như luận văn đồ án, sách, giáo trình, đề thi.
Chúng tôi không chịu trách nhiệm liên quan đến các vấn đề bản quyền nội dung tài liệu được thành viên tự nguyện đăng tải lên, nếu phát hiện thấy tài liệu xấu hoặc tài liệu có bản quyền xin hãy email cho chúng tôi.
Đã phát hiện trình chặn quảng cáo AdBlock
Trang web này phụ thuộc vào doanh thu từ số lần hiển thị quảng cáo để tồn tại. Vui lòng tắt trình chặn quảng cáo của bạn hoặc tạm dừng tính năng chặn quảng cáo cho trang web này.