|
Hi All, Thanking you all in advance for your effort.
(comments are locked)
|
|
I think this is what you want. It's clunky, because your table is not well defined. If it had a primary key, then I would have joined from the table onto itself, and done the filtering in a sub query. Here is the less clunky version. Note the NON NULLABLE PRIMARY KEY definition of Candidate. Yes sir, this is what I want.. Just one more question, Do I need any where condition for the candidates?
Nov 03 '10 at 02:39 AM
Gogolo
Looks OK, but I need small explanation why: M12 is equal with CASE WHEN DATEADD(m, 11, @baseDate)?? [M12] = CASE WHEN DATEADD(m, 11, @baseDate) BETWEEN [FilteredRegDate] AND [FilteredRemDate] THEN 1 ELSE 0 END
Nov 03 '10 at 02:55 AM
Gogolo
@Gogolo - You just need to set the @updateYear variable to what you want. The reason why month 12 is +11 is because 1 + 11 = 12. @baseDate is in January. If you add 1 month, you get February (month 2), if you add 2 months, you get March (month 3) ... if you add 11 months, you get December (month 12).
Nov 03 '10 at 03:08 AM
Matt Whitfield ♦♦
Thank you very much for your explanation and thank you all for solution. Fr sure that I will have more question regarding this query, because this is only a part from whole query. thank you all again
Nov 03 '10 at 04:01 AM
Gogolo
@Gogolo - If the answer is what you wanted, then use the tick to mark it as the accepted answer...
Nov 03 '10 at 04:21 AM
Matt Whitfield ♦♦
(comments are locked)
|
|
I think is what you need: +1, but might be worth adding the
Nov 03 '10 at 01:58 AM
Matt Whitfield ♦♦
good point .... wait there .... brb
Nov 03 '10 at 02:09 AM
Fatherjack ♦♦
Yes sir, it shoulb like that, but sometime I have registration date on 2004 and removed date on 2012, and I need updates only for 2010??
Nov 03 '10 at 02:09 AM
Gogolo
@gogolo - i have added a year filter.
Nov 03 '10 at 02:11 AM
Fatherjack ♦♦
@gogolo - sorry, I had > instead of =. try the code now I have edited it. Also please use the comment option rather than adding answers when you need to add information. Thanks
Nov 03 '10 at 02:28 AM
Fatherjack ♦♦
(comments are locked)
|


Yes, but nothing updated... My question was wrong for sure.. I didnt asked properly..
I will put some other data in table.At the candidate 1 registration date is 2006 and removable date 11.2010, he needs to have 1.2.3.4.5.6.7.8.9.10.11 set to 1 becose he is there between those dates.Maybe my clarification again is not so good, I apologise for that. THANK YOU AGAIN IN ADVANCES