0

I have a table that have these values:

From data   | Todate     | is_Complete

2018-11-01 |  2018-11-15   |    True
2018-11-16 | 2018-11-30   |    True

We are executing data every 1st day of the month. So assuming that It's already 1st day of december. I need to check if is_Complete column is True from first day of the previous month and 16th up to last day of the previous month then process my queries but if one of those is False I will not process it.

I am not sure if CAST will work here.

IF both is_Complete == True, then

process queries ELSE 'N/A'

1
  • I already have query on how to get the is_complete status: SELECT * FROM AA_WC_TEST_PAYRUN WHERE from_date = (select DATEADD(MONTH, DATEDIFF(MONTH, 0, GETDATE())-1, 0)) SELECT * FROM AA_WC_TEST_PAYRUN WHERE to_date = (select DATEADD(MONTH, DATEDIFF(MONTH, -1, GETDATE())-1, -1)) However, How can I use this on IF Statement before running another query – Mor Nov 22 '18 at 9:41
0
declare @AA_WC_TEST_PAYRUN table(from_date date, to_date date, is_Complete varchar(10));
insert into @AA_WC_TEST_PAYRUN 
values
('2018-10-01', '2018-10-15', 'True'),
('2018-10-16', '2018-10-30', 'True');

if (select is_Complete
    from @AA_WC_TEST_PAYRUN
    where from_date = (select dateadd(month, datediff(month, 0, getdate())-1, 0))) = 'True'
and
    (select is_Complete
    from @AA_WC_TEST_PAYRUN
    where from_date = (select dateadd(day, 15, dateadd(month, datediff(month, 0, getdate())-1, 0)))) = 'True'
begin
   print 'both true';
   -- other statements
end;
1
  • Thank you for your help. it works @Sepupic – Mor Nov 23 '18 at 2:08

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.