|
|
-
Peso Commented 1 Years ago through Just Learned | 1 Point
Dishdy, it does work even with "999" milliseconds, if you choose the correct datatype to begin with.
DECLARE @Today DATETIME2(3) = '2012-03-31 23:59:59.999'
SELECT DATEADD(MONTH, DATEDIFF(MONTH, '19000401', @Today) / 12 * 12, '19000401')
Confic...
|
-
Peso Commented 1 Years ago through Just Learned | 1 Point
Dishdy, it does work even with "999" milliseconds, if you choose the correct datatype to begin with.
DECLARE @Today DATETIME2(3) = '2012-03-31 23:59:59.999'
SELECT DATEADD(MONTH, DATEDIFF(MONTH, '19000401', @Today) / 12 * 12, '19000401')
Confic...
|
-
Peso Commented 1 Years ago through Just Learned | 1 Point
Beware that omitting the ROWS/RANGE BETWEEN clause makes SQL Server default to RANGE BETWEEN UNBOUNDED PRECEDING AND CURRENT ROW, which is disk spooled.
To force a memory spool, you should write ROWS BETWEEN UNBOUNDED PRECEDING AND CURRENT ROW, which i...
|
-
Peso Commented 1 Years ago through Just Learned | 1 Point
Beware that omitting the ROWS/RANGE BETWEEN clause makes SQL Server default to RANGE BETWEEN UNBOUNDED PRECEDING AND CURRENT ROW, which is disk spooled.
To force a memory spool, you should write ROWS BETWEEN UNBOUNDED PRECEDING AND CURRENT ROW, which i...
|
-
Peso Liked 1 Years ago through Just Learned | 1 Point
This script shows how to find the beginning of current financial year (for countries using April 1 as the beginning) using TSQL.
SELECT
DATEADD(dd,0,
DATEDIFF(dd,0,
DATEADD(
mm,
-(((12 + DATEPART(m, GETDATE())) - 4)%12),
G...
|
-
Peso incorrect 1 Years ago through Just Learned | 1 Point
This script shows how to find the beginning of current financial year (for countries using April 1 as the beginning) using TSQL.
SELECT
DATEADD(dd,0,
DATEDIFF(dd,0,
DATEADD(
mm,
-(((12 + DATEPART(m, GETDATE())) - 4)%12),
G...
|
-
Peso Commented 1 Years ago through Just Learned | 1 Point
1. If you replace GETDATE() with the date of 2012-03-31 you get 2012-03-31 as result. Even 2012-05-31 gives a result of 2012-03-31!
2. If you use DATE instead of DATETIME for @Today, your query fails due to inconsistent data types.
You tip above giv...
|
-
Peso Commented 1 Years ago through Just Learned | 1 Point
1. If you replace GETDATE() with the date of 2012-03-31 you get 2012-03-31 as result. Even 2012-05-31 gives a result of 2012-03-31!
2. If you use DATE instead of DATETIME for @Today, your query fails due to inconsistent data types.
You tip above giv...
|
-
Peso incorrect 1 Years ago through Just Learned | 1 Point
This script shows how to find the beginning of current financial year (for countries using April 1 as the beginning) using TSQL.
SELECT
DATEADD(dd,0,
DATEDIFF(dd,0,
DATEADD(
mm,
-(((12 + DATEPART(m, getDate())) - 4)%12),
...
|
-
Peso Commented 2 Years ago through Just Learned | 1 Point
It's called Composable DML....
|