Home > Mobile >  Select and Convert Date Of Birth from a table to check if their birthdays are today
Select and Convert Date Of Birth from a table to check if their birthdays are today

Time:01-26

I have a table called Genericattribute. It's as shown here.

enter image description here

enter image description here

I need to make a Trigger or a query that checks if today is the birthday of any of these employees.

I wrote a query that returns the Ids of the people along with their birthdays.

select [id],[value] from [Genericattribute]
where [key] = 'DateOfBirth'

It returned this output.

enter image description here

The date of births here are of the int type. Not the Date type.

I am unable to figure out how I can write a query that converts these int values to the date.

I have tried to use the getdate() to check today's date/time. Could not find any solution to figure this problem.

CodePudding user response:

Just a thought. Since [value] appears to be a string.

where [key] = 'DateOfBirth'
  and right(value,5)=format(getdate(),'MM-dd')

I normally shy away from format() due to the performance issues, but in this example it would be resolved once.

  • Related