sql - Storing the previous month as a char with a leading 0 for single digit months -
I have a field filled with dates, but they are stored in varchars as they are in the following format:
I am trying to write a query that will only allow the following three parameters The last four characters of Year My efforts lasted me The month and the previous month have stopped trying to store in two variables, and then on varchar "date" a LEFT () and right () "to see if they match those two variables." / P> The problem is that MONTH is being stored as a digit, and I It needs to be stored in the form of "0" + month digits (only in the case of single digit months), except that it is not working just for the year, so it is completely closed. Hope someone can help you! Even what I have so far: In fact, you need to change the "date" to "date" in the ISO standard Simple demo < / Html>
DECLARE @MONTHAgo date expiration @MonthString char DECLARE @YearString char SET @monthAgo = DATEADD (month, -1, GETDATE ()) SET @MonthString = MONTH (@MonthAgo) - SET @YearString = YEAR (@MonthAgo) is not working - Not working Except (*) jwemaildb.LogFileRecords WHERE date & gt; = DATEADD (month, DATEDIFF (month, 0, gaterate ()) - 1, 0) and date & lt; DATEADD (month, DATEDIFF (month, 0, GETDATE ()), 0) and right (eAlertSentDate, 4) = @YearString and left (eAlertSentDate, 2) = @MonthString < P>
SELECT COUNT (* ) Logfilereaks from jwemaildb where date & gt; = DATEADD (month, DATEDIFF (month, 0, gaterate ()) - 1, 0) and date & lt; DATEADD (1, DAY, (GETDATE ()), DATEADD (date, DATEDIFF (month, 0, GETDATE ()), 0) and CAST (right (eAlertSentDate, 4) + LEFT (eAlertSentDate, 4) AS date) DATEADD Mm / -1, GETDATE ()) and DATEADD (DD, 1 - DAY (GETDATE ()), GETDATE ())
Comments
Post a Comment