简体   繁体   中英

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

I have a table called Genericattribute. It's as shown 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.

在此处输入图像描述

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.

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM