SQL SERVER 2012 - pull data from only, if value date is available
-
Hi I wish to only begin a select statement if the top value date is found - this the first of the month. It's my way of knowing data has been added into a system at the beginning of the month e.g max date is 01/11/2018. If not take the last day of the previous month 31/10/2018. Table is called sales. Column is called SaleDateFrom. I want to pull e.g data from SaleDateFrom <=01/11/2018...if not pull data SaleDateFrom <=31/10/2018 statement to change where (SaleDateFrom<= '20181101' and (SaleDateTo '20010101' or SaleDateTo is null)) Any ideas team?
-
Hi I wish to only begin a select statement if the top value date is found - this the first of the month. It's my way of knowing data has been added into a system at the beginning of the month e.g max date is 01/11/2018. If not take the last day of the previous month 31/10/2018. Table is called sales. Column is called SaleDateFrom. I want to pull e.g data from SaleDateFrom <=01/11/2018...if not pull data SaleDateFrom <=31/10/2018 statement to change where (SaleDateFrom<= '20181101' and (SaleDateTo '20010101' or SaleDateTo is null)) Any ideas team?
-
This is exactly the same question as Only begin select if value is found in dataset sql - Database Discussion Boards[^] right below here. Did you create a new account just to repost this?
-
hi I don't know whats happened sorry...I tried so hard to edit the previous post, and it would not let me, so I signed out , went to log in it said denied, asked for reset I think it has issues if you login with facebook as uses same email. please help
-
Hi I wish to only begin a select statement if the top value date is found - this the first of the month. It's my way of knowing data has been added into a system at the beginning of the month e.g max date is 01/11/2018. If not take the last day of the previous month 31/10/2018. Table is called sales. Column is called SaleDateFrom. I want to pull e.g data from SaleDateFrom <=01/11/2018...if not pull data SaleDateFrom <=31/10/2018 statement to change where (SaleDateFrom<= '20181101' and (SaleDateTo '20010101' or SaleDateTo is null)) Any ideas team?
Not only is this a repost of the question below, you haven't responded to any of the questions asked in response to that post.
2018-10-31
is less than2018-11-01
; therefore, if there are no records withSaleDateFrom <= '20181101'
, there will be no records withSaleDateFrom <= '20181031'
. You need to explain what you're actually trying to achieve.
"These people looked deep within my soul and assigned me a number based on the order in which I joined." - Homer
-
Not only is this a repost of the question below, you haven't responded to any of the questions asked in response to that post.
2018-10-31
is less than2018-11-01
; therefore, if there are no records withSaleDateFrom <= '20181101'
, there will be no records withSaleDateFrom <= '20181031'
. You need to explain what you're actually trying to achieve.
"These people looked deep within my soul and assigned me a number based on the order in which I joined." - Homer
I'm doing my best to explain , here is my where clause where (SaleDateFrom<= '20181101' and (SaleDateTo '20010101' or SaleDateTo is null)) I want to replace the date in bold to 20181031 if the highest date entered into the data base is not the 20181101. this is to make sure the data for the start of the month has been entered please help please see response to Richard - about account big issue, which I be contacting code project about
-
I'm doing my best to explain , here is my where clause where (SaleDateFrom<= '20181101' and (SaleDateTo '20010101' or SaleDateTo is null)) I want to replace the date in bold to 20181031 if the highest date entered into the data base is not the 20181101. this is to make sure the data for the start of the month has been entered please help please see response to Richard - about account big issue, which I be contacting code project about
And once again: If there are no records where the
SaleDateFrom
is on or before 1st November, then there will be no records whereSaleDateFrom
is on or before 31st October. If there is a record for 31st October, then that will already be included in your current query. If there are no records on or before 1st November, then changing your query to look for records with an earlier date isn't going to make any difference.
"These people looked deep within my soul and assigned me a number based on the order in which I joined." - Homer
-
And once again: If there are no records where the
SaleDateFrom
is on or before 1st November, then there will be no records whereSaleDateFrom
is on or before 31st October. If there is a record for 31st October, then that will already be included in your current query. If there are no records on or before 1st November, then changing your query to look for records with an earlier date isn't going to make any difference.
"These people looked deep within my soul and assigned me a number based on the order in which I joined." - Homer
-
I'm doing my best to explain , here is my where clause where (SaleDateFrom<= '20181101' and (SaleDateTo '20010101' or SaleDateTo is null)) I want to replace the date in bold to 20181031 if the highest date entered into the data base is not the 20181101. this is to make sure the data for the start of the month has been entered please help please see response to Richard - about account big issue, which I be contacting code project about
Why don't you use a sub-select for the date?
where (SaleDateFrom <= ( select max(your date column) from your table with date value ) and (SaleDateTo '20010101' or SaleDateTo is null ))