Help for a stored Procedure
My Customer table stores the age or the birsthday of the customer but
one of them is set. I want to get the customer's name and age. So have
to compute the customer's age from his birthday if age is set to null
or get directly his age if birthday is set to null . I resolved my
problem by writing this C# code that modify a dataset wgich contains
the name, age and birthday columns.
DataColumn dc = new DataColumn("FinalAge", System.Type.GetType("System.Int32"));
//add my FinalAge column
res.Tables[0].Columns.Add(dc);
//and compute its value
foreach (DataRow row in res.Tables[0].Rows)
{
if (row["Age"].ToString()==string.Empty)
{
DateTime birth = Convert.ToDateTime(row["Birthday"]);
int years = DateTime.Now.Year - birth.Year;
if (DateTime.Now.Month < birth.Month || (DateTime.Now.Month == birth.Month && DateTime.Now.Day < birth.Day))
years--;
row["FinalAge"] = years;
}
else row["FinalAge"] = row["Age"];
}
Now I want to transform this code to a stored procedure or even a sql query if it is possible.
Any suggestion ?
Thanks in Advance

