I have been given a part of a project financial reporting system to work. In fact, I'm trying to modify an existing query so that the result can be returned and returned to a field that is a variable date format.
My query is being sent twice in the YYYY format with any elses code, so 2014 and 2017. In the SQL query below, they are listed as 2014 and 2017, so you can see them in variables Form.
Fields in databases that come in variable dates form two forms:. YYYYMMDD or YYYYMM
looks like an existing query:
select 'Spend' type, in the form of dbo.Department.Description [country name], form of dBO In. As JCdescription.Description, as dbo.Detail.AccountCode [Fin Code], as dbo.JCdescription.ReportCode1 [Start Date Date], dbo.JCdescription.ReportCode2 [phase date end], as dbo As per JCdescription.ReportCode3 [Date of ratification], DB.Ditrate. As the year [transaction year], join dbo.Detail INNER as dbo.Detail.Period [transaction year period], ... ... WHERE (dbo.Detail.LedgerCode = 'jc'). And (dbo.Detail.Year) between '2014 and 2017';
Ideally I want to change the last line:
(like 'dbo.JCdescription.ReportCode2' '[2014-2017]%' )
But between 2014 and 2017 it searches all 2,0,1,4,5 points instead of all things.
I'm sure I should remember something simple here, but I can not find it! I think I can express it differently as 'code' as '201 [4567]%' but this means that 2010-2020 will be the out-of-the-error searches .. and me Which will send an additional function to parse the variables sent, which will be said very much. I did not want to do it, I just need two numbers, as the whole number instead of 4 digits of 2014 and 2017 To be treated!
MS SQL Server 10.0.5520
I think that You can use the system function if any of your date columns are given.
This will allow you to type something that looks pretty much like the following.
where between the year (MyDateColumn) 2014 and 2017
In addition to this, you are using the date column as the data type, They will be for comparable values, and you also need to make sure you need a comparison.
So assume that you have string values like '201505' dateStringColumn
.
where between dast (2017 and 2017 between 2014) (substring (dateStringColumn, 1, 4))
No comments:
Post a Comment