Hi,
I have to compare every row in month column in xyz table with current month. If there is mismatch, then error message must be displayed.
I have used DATEDIFF (MM, Select getdate(), select month from xyz ), but I am getting error at MM. Can anybody fix this issue.
The syntax you have is incorrect. Try something like this:
SELECT [Month], Mismatch=CaseWHENMonth(Getdate())= [Month]then 0ELSE 1ENDFROM MyTable
|||This will work:
1SELECT MonthColumn,2 IsMatchColumn =3CaseWHENDatePart(Month,GetDate()) = MonthColumn4Then 0-- Yes (Matched)5Else 1-- No (Not Matched)6END78FROM YourTableName9
Good luck.
No comments:
Post a Comment