How to display only YEAR by Solr - solr

How to return the year from a full date in Solr
2019-12-20 14:05:38.327 -> 2019

Related

Using SQL/Report Builder, how can I make column headers show Month and Year?

I have a query that has 4 parameters:
#StartDate date
#EndDate date
#PreviousStartDate date
#PreviousEndDate date
Which pulls data for the selected year and one year back, grouped by month. It is showing selected month compared to previous month one year back.
Table looks like:
Month
PreviousMonthValues
CurrentMonthValues
1
Value
Value
2
Value
Value
3
Value
Value
Where 1 = January, 2 = February, 2 = March, etc.
Problem:
I am using Microsoft Report Builder, and want to create dynamic headers that show ‘December 2019 vs December 2018’, is there a way to do this?
I have tried:
MonthName(Fields!Month.Value) & " " &DatePart("yyyy")'=(DATEADD("yyyy",-1,Parameters!startdate.Value))) & " v " & MonthName(Fields!Month.Value) & " "
& DatePart("yyyy",Parameters!startdate.Value)
But this does not work for all cases. If StartDate is ‘12/01/19’ then the year for each month would be: ‘December 2019 vs December 2018’, ‘January 2019 vs January 2018’, etc., when it should be ‘January 2020 vs January 2019’
Is there a way to accomplish this by either restructuring data, or in Report Builder?

SQL insert first of month

I've created an initial sql insert into a table, below.
spool_month spool_year spool_month_part spool_year_part curr_cnt prev_cnt cal_prcnt_dff
July 2020 7 2020 21069199 NULL 0
September 2020 9 2020 18072707 21069199 14
October 2020 10 2020 17284440 18072707 4
November 2020 11 2020 17791289 17284440 3
December 2020 12 2020 20148679 17791289 13
January 2021 1 2021 22543049 20148679 12
February 2021 2 2021 24234982 22543049 8
March 2021 3 2021 26458351 24234982 9
April 2021 4 2021 5946066 26458351 78
Can I create an insert that would only insert new data into this table at the first of the month? So, for example at first of every month insert previous months data.
Not sure where to start with this piece, so any feedback would be appreciated.
This is easily solved by using SqlAgent; if you are only using SqlExpress you won't have access to SqlAgent, in which case you will need to look at using the Windows Task Scheduler and Powershell, if that's the case here is a useful guide
Create your procedure that will perform your insert and schedule it to run daily either from a SqlAgent Job or Powershell from link above.
In your procedure, wrap your insert with
if DatePart(day,GetDate())=1
begin
...
end

Convert int to date in SQL Server vs Excel

EXCEL: When I format the number 43466 as a date I get 1/1/2019
SQL Server: CAST(43466 AS DATETIME) yields Jan 3 2019
Which is correct?
How can I get the correct date in SQL Server?

Vehicle Fitment Data Merge Overlapping Years

I have a large data set of vehicle fitment information for products, each on their own row.
I am struggling to create a query to select only the minimum and maximum years for each overlapping entry.
For example, I have data such as:
fromyear toyear makename modelname submodelname wheelbase BedLength BedTypeName bodytype note1 Note2 note3 partterminologyname exppartno
2008 2012 Chevrolet Silverado 1500 LT NULL 78.00 Fleetside NULL Black NULL NULL Truck Bed Mat 37807
2010 2010 Chevrolet Silverado 1500 LT NULL 78.00 Fleetside NULL Black NULL NULL Truck Bed Mat 37807
2014 2017 Chevrolet Silverado 1500 LT NULL 78.00 Fleetside NULL Black NULL NULL Truck Bed Mat 37807
I am not concerned with keeping the data, so I've moved my focus to an UPDATE query by selecting the minimum and maximum years, but adding something like
(SELECT MIN(p2.fromyear)
FROM prod AS p2
WHERE p1.fromyear > 0
AND p2.toyear >= p1.fromyear
AND p2.fromyear < p1.fromyear
AND ISNULL(p2.makename, '') = ISNULL(p1.makename, '')
AND ISNULL(p2.modelname, '') = ISNULL(p1.modelname, '')
AND ISNULL(p2.submodelname, '') = ISNULL(p1.submodelname, '')
AND ISNULL(FLOOR(p2.wheelbase), 0) = ISNULL(FLOOR(p1.wheelbase), 0)
AND ISNULL(FLOOR(p2.BedLength), 0) = ISNULL(FLOOR(p1.BedLength), 0)
AND ISNULL(p2.BedTypeName, '') = ISNULL(p1.BedTypeName, '')
AND ISNULL(p2.bodytype, '') = ISNULL(p1.bodytype, '')
AND ISNULL(p2.note1, '') = ISNULL(p1.note1, '')
AND ISNULL(p2.Note2, '') = ISNULL(p1.Note2, '')
AND ISNULL(p2.note3, '') = ISNULL(p1.note3, '')
AND ISNULL(p2.exppartno, '') = ISNULL(p1.exppartno, '')) AS newfrom
causes the query to run for an excessive amount of time (pulling from a table with over 150k rows).
After doing an UPDATE to merge the years, I can simply remove any duplicate rows.
The desired result would return only two rows for this model, 2008-2012 and 2014-2017
My original idea was to simply select MIN(fromyear) and MAX(toyear), however this leaves me with an issue of having the invalid year of 2013 as an option.
Is there some simple way to formulate a query to handle overlapping years like this? Everything I found in my searches did not involve matching multiple columns of data.
I would suggest joining onto a date table, with a list of sequential years as follows (to cover the full range of years in the source data):
year
-----
...
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
...
So joining your source table to the date table ON (year >= fromyear AND year <= toyear), gives the following results:
year fromyear toyear vehicle_descriptor
2008 2008 2012 Chevrolet...
2009 2008 2012 Chevrolet...
2010 2008 2012 Chevrolet...
2011 2008 2012 Chevrolet...
2012 2008 2012 Chevrolet...
2010 2010 2010 Chevrolet...
2014 2014 2017 Chevrolet...
2015 2014 2017 Chevrolet...
2016 2014 2017 Chevrolet...
2017 2014 2017 Chevrolet...
Then group (or select distinct) the rows to eliminate duplicate years. (I'm using "vehicle_descriptor" as a shorthand for all the columns that uniquely identify a vehicle in your source data.)
On the deduplicated results, add a column as follows:
(year - ROW_NUMBER() OVER (PARTITION BY vehicle_descriptor ORDER BY year ASC) ) AS year_group
This produces a unique number for every year or continuous sequence of years.
year fromyear toyear veicle_descriptor row_number year_group (year - row_number)
2008 2008 2012 Chevrolet... 1 2007
2009 2008 2012 Chevrolet... 2 2007
2010 2008 2012 Chevrolet... 3 2007
2011 2008 2012 Chevrolet... 4 2007
2012 2008 2012 Chevrolet... 5 2007
2010 2010 2010 Chevrolet... (this row removed as year 2010 is a duplicate)
2014 2014 2017 Chevrolet... 6 2008
2015 2014 2017 Chevrolet... 7 2008
2016 2014 2017 Chevrolet... 8 2008
2017 2014 2017 Chevrolet... 9 2008
Finally, once you have this year_group, simply group the rows in the way you originally envisaged, by vehicle_descriptor and year_group, and select the MIN(year) and MAX(year).
The year_group value has no particular significance is not retained in the final results - it's just there to differentiate the sequences. It works because it increments every time there is a discontinuity in the year sequence (and it increments by the amount of discontinuity).
I hope I've explained that satisfactorily. I'm not at my desktop PC, so I've written it all out by hand! If there's anything unclear, or you need a code example, let me know and I'll come back to you.

Angularjs - Format date (13 January 2016)

I have the next date:
<p>{{customer.date | date : "fullDate"}}</p>
I would like to have this format: 13 January 2016
I am testing with formats different but dont get it.
How could i do it? thanks,
Take a look at the AngularJS documentation: https://docs.angularjs.org/api/ng/filter/date
<p>{{customer.date | date : "dd MMMM y"}}</p>

Resources