October 30, 2018 at 2:57 pm
i have the data if AFG is Yes or Type is N/A then we need to count as 1 valid record
Condition 1
AFG Type
yes N/A
COnditon 2 - If AGF is No or Type is Phys then we need to count as another valid record
AFG Type
No Phys
Also for these both conditions we have to check the record is active or not, for that we need to check start date should be less than current date and end date should be future data.. if it is valid then only we can check both the oncditons
October 30, 2018 at 4:36 pm
mcfarlandparkway - Tuesday, October 30, 2018 2:57 PMi have the data if AFG is Yes or Type is N/A then we need to count as 1 valid record
Condition 1
AFG Type
yes N/ACOnditon 2 - If AGF is No or Type is Phys then we need to count as another valid record
AFG Type
No Phys
Also for these both conditions we have to check the record is active or not, for that we need to check start date should be less than current date and end date should be future data.. if it is valid then only we can check both the oncditons
You should know the deal by now. For any help we need DDL, sample data and expected results. I'd also like to know what have you tried as a simple CASE expression should do the trick.
October 31, 2018 at 1:38 am
mcfarlandparkway - Tuesday, October 30, 2018 2:57 PMi have the data if AFG is Yes or Type is N/A then we need to count as 1 valid record
Condition 1
AFG Type
yes N/ACOnditon 2 - If AGF is No or Type is Phys then we need to count as another valid record
AFG Type
No Phys
Also for these both conditions we have to check the record is active or not, for that we need to check start date should be less than current date and end date should be future data.. if it is valid then only we can check both the oncditons
Adding to what Luis said I think you need to use count and case expression along with group by function
Saravanan
October 31, 2018 at 7:00 am
Something like this:
SELECT
[RowIsValid] = CASE
WHEN AFG = 'Yes' OR [Type] = 'N/A' THEN 1
WHEN AGF = 'No' OR [Type] = 'Phys' THEN 2
END,
[RowIsActive] = CASE WHEN [start date] < GETDATE() AND [end date] > GETDATE() THEN 1 ELSE 0 END
As others have stated, much easier to do when sample data is provided.
For fast, accurate and documented assistance in answering your questions, please read this article.
Understanding and using APPLY, (I) and (II) Paul White
Hidden RBAR: Triangular Joins / The "Numbers" or "Tally" Table: What it is and how it replaces a loop Jeff Moden
Viewing 4 posts - 1 through 3 (of 3 total)
You must be logged in to reply to this topic. Login to reply