SQL is also used to retrieve relevant data from the database.
This is part of a bigger where clause, the proc returns a list of people who's birthdays are coming up in the next X days.
Thanks everyone for the responses!!
SQL is also used to retrieve relevant data from the database.
This is part of a bigger where clause, the proc returns a list of people who's birthdays are coming up in the next X days.
Thanks everyone for the responses!!
Thank you for the response.
Using your test case '<font color="#ff0000" size="2">1976-02-29'</font><font size="2"> </font><font color="#808080" size="2"></font>in the code I originally posted gives me a results of '2007-02-28 00:00:00.000' which I think is correct (this is SQL Server 2005 if that makes a difference). Thank you though I hadn't considered Feb-29th.
I just really hate how my code looks. So I'll probably go to yours just because it is more readable.
Thanks again!!!
So I am trying to figure out in SQL (SQL Server 2005) how to get the date of your next birthday given your birthdate. I have some SQL code that works, but it is ugly, can anyone see a way to clean this up? Or a better way to do it (SQL is not my strong point).
Thanks
<font color="#0000ff" size="2">
DECLARE<font size="2"> @BirthDate </font><font color="#0000ff" size="2">DATETIME</font><font size="2"> </font>
</font>DECLARE<font size="2"> @BirthDate </font><font color="#0000ff" size="2">DATETIME</font><font size="2"> </font>
<font size="2"></font>
<font color="#0000ff" size="2">SET<font size="2"> @BirthDate </font><font color="#808080" size="2">=</font><font size="2"> </font><font color="#ff0000" size="2">'19810409'</font><font size="2"> </font></font><font color="#0000ff" size="2">SELECT<font size="2"> </font><font color="#ff00ff" size="2">dateAdd</font><font color="#808080" size="2">(</font><font color="#ff00ff" size="2">year</font><font color="#808080" size="2">,</font><font size="2"> </font><font color="#ff00ff" size="2">convert</font><font color="#808080" size="2">(</font><font color="#0000ff" size="2">int</font><font color="#808080" size="2">,</font><font size="2"> </font><font color="#ff00ff" size="2">Year</font><font color="#808080" size="2">(</font><font color="#ff00ff" size="2">GetDate</font><font color="#808080" size="2">()</font><font size="2"> </font><font color="#808080" size="2">-</font><font size="2"> @Birthdate</font><font color="#808080" size="2">)</font><font size="2"> </font><font color="#808080" size="2">-</font><font size="2"> 1899</font><font color="#808080" size="2">),</font><font size="2"> @Birthdate</font><font color="#808080" size="2">)</font>
</font>