October 26, 2017 at 5:54 pm
I have a date column below RunDate , I want to create two column StartDate and EndDate like this StartDate = '2004-08-01' EndDate = '2006-08-01' second row StartDate = '2006-08-02' EndDate = '2007-02-15
how do I do this SQL missing row could be null or empty string
RunDate |
8/1/2004 |
11/1/2004 |
8/1/2006 |
missing row |
8/2/2006 |
2/15/2007 |
missing row |
2/16/2007 |
2/17/2007 |
2/22/2007 |
October 26, 2017 at 6:08 pm
I see no rhyme or reason to how you are putting together your start and end dates based on the dates posted. Care to explain this a little better?
October 26, 2017 at 6:15 pm
Well basically my Rundate column is in ascending order and I have to setstart and enddate range every time row is null or empty. so after null column will be start date and before null column is end date
October 26, 2017 at 7:59 pm
Redmond01 - Thursday, October 26, 2017 6:15 PMWell basically my Rundate column is in ascending order and I have to setstart and enddate range every time row is null or empty. so after null column will be start date and before null column is end date
Your original post didn't match that description. According to what you wrote above, the second start date should be 2006-08-02 instead of 2004-08-02, correct?
--Jeff Moden
Change is inevitable... Change for the better is not.
October 26, 2017 at 10:36 pm
Redmond01 - Thursday, October 26, 2017 6:15 PMWell basically my Rundate column is in ascending order and I have to setstart and enddate range every time row is null or empty. so after null column will be start date and before null column is end date
What determines the order of the rows? (and don't say RunDate, because if it was, both of those missing rows would sort first)
Are you really using SQL Server 2017?
Gail Shaw
Microsoft Certified Master: SQL Server, MVP, M.Sc (Comp Sci)
SQL In The Wild: Discussions on DB performance with occasional diversions into recoverability
October 27, 2017 at 12:31 am
Correct Jeff Moden start date should be 2006-08-02 instead of 2004-08-02, hat was a type .
October 27, 2017 at 9:56 am
Redmond01 - Friday, October 27, 2017 12:31 AMCorrect Jeff Moden start date should be 2006-08-02 instead of 2004-08-02, hat was a type .
Now you need to answer Gail's question.
October 27, 2017 at 11:47 am
I'm pretty I now see what the original poster is after. Apparently whenever ISNULL(RunDate, '') = '', he/she wants a pair of dates representing the range of dates encountered since the last such condition. However, as we have no expected output, and RunDate, assuming it's actually a date kind of data type, isn't going to be able to handle multiple date values in the same row, so we're forced to assume that a new pair of columns is needed. We also have to presume what values those columns should have for any row where the stated condition is NOT true. What say you, Redmond01?
Steve (aka sgmunson) 🙂 🙂 🙂
Rent Servers for Income (picks and shovels strategy)
October 27, 2017 at 1:45 pm
Since there's no way to give a proper answer without further information, I'll just leave this article here that explains this kind of problem.
https://www.red-gate.com/simple-talk/sql/t-sql-programming/the-sql-of-gaps-and-islands-in-sequences/
October 27, 2017 at 4:27 pm
Redmond01 - Friday, October 27, 2017 12:31 AMCorrect Jeff Moden start date should be 2006-08-02 instead of 2004-08-02, hat was a type .
Ok. Then, like Gail said, we need a different column that preserves the order of the rows as you have them posted because NULLs will bubble to the top in a sort and you cannot rely on any kind of sort based only on the order of insert.
--Jeff Moden
Change is inevitable... Change for the better is not.
October 29, 2017 at 3:42 pm
Redmond01 - Sunday, October 29, 2017 3:04 PM@Lynn Pettis , why don't you keep you obnoxious ,sarcastic and dumb as rock remarks to yourself.
I see no where that Lynn has been any of these, and I feel confident in saying you have just lost any further advice you would have received on this topic, or possibly forum, with comments such as that.
There's no need to make derogatory remarks towards any one on these forums, especially when almost the entire community are volunteering their help and expertise completely free of charge and of their own time.
If nothing else, I would suggest an apology (to Lynn), if you'd like others to help you with getting the results you need from your data.
Thom~
Excuse my typos and sometimes awful grammar. My fingers work faster than my brain does.
Larnu.uk
October 29, 2017 at 10:47 pm
Redmond01 - Sunday, October 29, 2017 3:04 PM@Lynn Pettis , why don't you keep you obnoxious ,sarcastic and dumb as rock remarks to yourself.
Excuse me?? I have made no obnoxious, sarcastic, dumb as rock remarks.
Good luck with this and any other issues you may have.
October 30, 2017 at 1:58 am
Redmond01 - Sunday, October 29, 2017 3:04 PM@Lynn Pettis , why don't you keep you obnoxious ,sarcastic and dumb as rock remarks to yourself. Excuse me?? I have made no obnoxious, sarcastic, dumb as rock remarks. |
@Lynn Pettis are you threatening me , do you own this forum?
October 30, 2017 at 8:33 am
Redmond01 - Monday, October 30, 2017 1:58 AM
Redmond01 - Sunday, October 29, 2017 3:04 PM@Lynn Pettis , why don't you keep you obnoxious ,sarcastic and dumb as rock remarks to yourself. Excuse me?? I have made no obnoxious, sarcastic, dumb as rock remarks.
Good luck with this and any other issues you may have.
Lynn Pettis@Lynn Pettis are you threatening me , do you own this forum?
Are you some kind of bully? No one has threatened you... and all they've said is that it's unlikely anyone here will want to help someone who posts what amounts to some rather inflammatory statements that are neither accurate nor reasonable. That does not constitute a threat. They're just advising you that making such remarks is a good way to avoid getting any help at all. Most everyone posting on this forum is a volunteer, including me. The forum is owned by RedGate software, and frankly, I'm of the opinion your ability to post here may be in jeopardy with this kind of post clearly being a repeated problem, as it appears from the post history that your first such post was removed... I'll be reporting this post of yours, as it's clear you just don't understand how a forum such as this works.
Steve (aka sgmunson) 🙂 🙂 🙂
Rent Servers for Income (picks and shovels strategy)
October 30, 2017 at 8:48 am
Redmond01 - Monday, October 30, 2017 1:58 AM
Redmond01 - Sunday, October 29, 2017 3:04 PM@Lynn Pettis , why don't you keep you obnoxious ,sarcastic and dumb as rock remarks to yourself. Excuse me?? I have made no obnoxious, sarcastic, dumb as rock remarks.
Good luck with this and any other issues you may have.
Lynn Pettis@Lynn Pettis are you threatening me , do you own this forum?
Again, excuse me?? I am not threatening you in any way. I will tell you that I will not be helping you now or in the future after this latest outburst. That is my choice as a volunteer on this site.
Viewing 15 posts - 1 through 15 (of 26 total)
You must be logged in to reply to this topic. Login to reply