Silly SQL
-
SELECT MONTH + MONTH(DATEADD(qq,-1,DATEADD(qq,DATEDIFF(qq,0,@Today),0))) - 1
FROM table1 t JOIN (SELECT TOP 3 row_number() over (ORDER BY fieldA) as MONTH FROM AnyTable) B on 1 = 1The first MONTH is actually the aliased field name from B. Why alias a field using the same name as a built-in function? Very confusing to follow. Although, unfortunately, it does actually work. On the plus side, joining to AnyTable using Top 3 Row_Number() is a clever way to guarantee 3 rows. Guess I could also put this in the Clever Code but it was written by the same dev.
There are only 10 types of people in the world, those who understand binary and those who don't.
-
SELECT MONTH + MONTH(DATEADD(qq,-1,DATEADD(qq,DATEDIFF(qq,0,@Today),0))) - 1
FROM table1 t JOIN (SELECT TOP 3 row_number() over (ORDER BY fieldA) as MONTH FROM AnyTable) B on 1 = 1The first MONTH is actually the aliased field name from B. Why alias a field using the same name as a built-in function? Very confusing to follow. Although, unfortunately, it does actually work. On the plus side, joining to AnyTable using Top 3 Row_Number() is a clever way to guarantee 3 rows. Guess I could also put this in the Clever Code but it was written by the same dev.
There are only 10 types of people in the world, those who understand binary and those who don't.
ryanb31 wrote:
Although, unfortunately, it does actually work
Its an unfortunate issue that you posted the code saying unfortunately its work. Did you loose your job because of this unfortunate event?
-
ryanb31 wrote:
Although, unfortunately, it does actually work
Its an unfortunate issue that you posted the code saying unfortunately its work. Did you loose your job because of this unfortunate event?
-
ryanb31 wrote:
Although, unfortunately, it does actually work
Its an unfortunate issue that you posted the code saying unfortunately its work. Did you loose your job because of this unfortunate event?
-
SELECT MONTH + MONTH(DATEADD(qq,-1,DATEADD(qq,DATEDIFF(qq,0,@Today),0))) - 1
FROM table1 t JOIN (SELECT TOP 3 row_number() over (ORDER BY fieldA) as MONTH FROM AnyTable) B on 1 = 1The first MONTH is actually the aliased field name from B. Why alias a field using the same name as a built-in function? Very confusing to follow. Although, unfortunately, it does actually work. On the plus side, joining to AnyTable using Top 3 Row_Number() is a clever way to guarantee 3 rows. Guess I could also put this in the Clever Code but it was written by the same dev.
There are only 10 types of people in the world, those who understand binary and those who don't.
The bad practice is failing to write the statement explicitly. Why change MONTH when it's meant to be 'month'? The shame is not using "SELECT B.[MONTH] + MONTH..." Yet, even that is minor.