sql - Convert nvarchar to datetime for date range query -
My GLD (GL Account) table contains both the year and duration columns, the nature type.
My aim is to allow a user to select multiple dates in the query, for example, to search ...
- inpYearBegin: 2013 < Li> inpPieriodBegin: 3
- inpYearEnd 2014
- inpPeriodEnd: 12
But what is going on is that the result is 1 to 2 Will not show duration from 1 to 2. I think the fields need to be changed from time to time, but I'm not sure where to go from my SQL server query so far:
select GLD.GLD_EndingBalance , GLD.GLD_AcctNbr, GLD.GLD_Year, GLD.GLD_Period, Year (Cast (as GLD.GLD_Year date time)) GLD from where to year GLD.GLD_AcctNbr = '140000' and GLD.GLD_Year & gt; = 'Request.inpYearBegin ~' and GLD.GLD_Period & gt; = 'Request.inpPeriodBegin ~' and GLD.GLD_Year & lt; = 'Request.inpYearEnd ~' and GLD.GLD_Period & lt; = '@ Request.inpPeriodEnd ~'
All you need to do is
Where adds a bit to some brackets to control the comparison, something like this:
declared @FromYear int = 2013 declared @FromMonth int = 3 GLD T Announced (as the date of the GLD.GLD_Year date time) declared @ThruYear integer = 2014 declared @ThruMonth Integer = 12, t.GLD_EndingBalance, t.GLD_AcctNbr, t.GLD_Year, t.GLD_Period, year Where t.GLD_AcctNbr = '140000' and TGLL_AyAir @Fream Yar and @ Thurayyar and (TGLLUyri> gt; @firmier or T.GLDDeure & lt; @ ThruYear or (t.GLD_Year = @FromYear and t.GLD_Period & gt; = @FromMonth) or ( T.GLD_Year = @TruyYear and t.GLD_Period
The above should include gems from March 2013 to December 2014, inclusive.
Another way to get there is to use the functions of discrimination like:
select t.GLD_EndingBalance, t .GLD_AcctNbr, t.GLD_Year, t.GLD_Period, Year in the form of year from GLD T (cast (as GLD.GLD_Year date time)) where t.GLD_AcctNbr = '140000' and @FromYear and @ThruYear and t.GLD_Period between t.GLD_Year when in case .GLD_YEar = @FromYear So the rest @FromMonth 1 is the end and the case is t.GLD_YEAR = @ThruYear then the rest @ThrruMonth 12 end
that simple query, although I could not really To say that one other Comparison is easier to understand.
Perhaps more important, though:. It may happen (to emphasize may ) you get a better action plan by applying
Comments
Post a Comment