navigator703
MIS
Good afternoon all-
In this SQL code, we are looking for tenants with split month rents. We are working on trying to fix this rent problem to where it matches for the end of the month like normal rents do, but in the meanwhile, we need a list in order to fix them in the future. Right now this means that the rents are starting and ending at the middle of the months, instead of at the beginning. For example, the rent stops on the 14th and then starts on the 15th of each month. As of now it does work, but not to what we are looking for. We are looking more along the lines of showing each month, July 14th and July 15th. The code now is producing different years and months from each record. It is giving the correct months and all, but still. If you have any suggestions of making it cleaner or making it run quicker, we would be appreciative.
[!]Here is the code![/!]
If you have any questions or suggestions, please let me know. Thanks.
Navigator
In this SQL code, we are looking for tenants with split month rents. We are working on trying to fix this rent problem to where it matches for the end of the month like normal rents do, but in the meanwhile, we need a list in order to fix them in the future. Right now this means that the rents are starting and ending at the middle of the months, instead of at the beginning. For example, the rent stops on the 14th and then starts on the 15th of each month. As of now it does work, but not to what we are looking for. We are looking more along the lines of showing each month, July 14th and July 15th. The code now is producing different years and months from each record. It is giving the correct months and all, but still. If you have any suggestions of making it cleaner or making it run quicker, we would be appreciative.
[!]Here is the code![/!]
Code:
SELECT TNNT_ID, CST_CTR_CD, CO_CD, OBLIG_ID, CMNC_DT, EXPR_DT
FROM T_OBLIG
WHERE((MONTH(CMNC_DT) = 01 AND DAY(CMNC_DT) NOT IN (1,31)) OR
(MONTH(EXPR_DT) = 01 AND DAY(EXPR_DT) NOT IN (1,31))) OR
((MONTH(CMNC_DT) = 02 AND DAY(CMNC_DT) NOT IN (1,28)) OR
(MONTH(EXPR_DT) = 02 AND DAY(EXPR_DT) NOT IN (1,28))) OR
((MONTH(CMNC_DT) = 03 AND DAY(CMNC_DT) NOT IN (1,31)) OR
(MONTH(EXPR_DT) = 03 AND DAY(EXPR_DT) NOT IN (1,31))) OR
((MONTH(CMNC_DT) = 04 AND DAY(CMNC_DT) NOT IN (1,30)) OR
(MONTH(EXPR_DT) = 04 AND DAY(EXPR_DT) NOT IN (1,30))) OR
((MONTH(CMNC_DT) = 05 AND DAY(CMNC_DT) NOT IN (1,31)) OR
(MONTH(EXPR_DT) = 05 AND DAY(EXPR_DT) NOT IN (1,31))) OR
((MONTH(CMNC_DT) = 06 AND DAY(CMNC_DT) NOT IN (1,30)) OR
(MONTH(EXPR_DT) = 06 AND DAY(EXPR_DT) NOT IN (1,30))) OR
((MONTH(CMNC_DT) = 07 AND DAY(CMNC_DT) NOT IN (1,31)) OR
(MONTH(EXPR_DT) = 07 AND DAY(EXPR_DT) NOT IN (1,31))) OR
((MONTH(CMNC_DT) = 08 AND DAY(CMNC_DT) NOT IN (1,31)) OR
(MONTH(EXPR_DT) = 08 AND DAY(EXPR_DT) NOT IN (1,31))) OR
((MONTH(CMNC_DT) = 09 AND DAY(CMNC_DT) NOT IN (1,30)) OR
(MONTH(EXPR_DT) = 09 AND DAY(EXPR_DT) NOT IN (1,30))) OR
((MONTH(CMNC_DT) = 010 AND DAY(CMNC_DT) NOT IN (1,31)) OR
(MONTH(EXPR_DT) = 010 AND DAY(EXPR_DT) NOT IN (1,31))) OR
((MONTH(CMNC_DT) = 011 AND DAY(CMNC_DT) NOT IN (1,30)) OR
(MONTH(EXPR_DT) = 011 AND DAY(EXPR_DT) NOT IN (1,30))) OR
((MONTH(CMNC_DT) = 012 AND DAY(CMNC_DT) NOT IN (1,31)) OR
(MONTH(EXPR_DT) = 012 AND DAY(EXPR_DT) NOT IN (1,31)))
ORDER BY TNNT_ID
If you have any questions or suggestions, please let me know. Thanks.
Navigator