Click here to Skip to main content
15,886,788 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
SQL
DOB    datetime 
WEdding datetime 

SQL
Sql = "select s.Name,s.DOB,s.Mobileno,s.Weddingday from BirthDayWish s where s.Active <> 'D'";
                    Sql = Sql + " and year(DOB) <> '1900'";
                    Sql = Sql + " and month(DOB) = month('" + Convert.ToDateTime(CurDate) + "') and day(DOB) = day ('" + Convert.ToDateTime(CurDate) + "') ";
                    Sql = Sql + " or year(Weddingday) <> '1900'";
                    Sql = Sql + " or month(Weddingday) = month('" + Convert.ToDateTime(CurDate) + "')  or day(Weddingday) = day ('" + Convert.ToDateTime(CurDate) + "')";



sending sms for birthday and wedding day,

i have to use loop condition query apply and send the sms.

if year not equal to 1900 DONT send sms first to birthdaywish
then i use else stmt if year not equal to 1900 DONT send sms to wedding.
likewise
if year <> to 1900 send sms DOB date from database and send sms to birthday
then i use else stmt i year <> 1900 send sms to wedding.

i send the above query from the above query how to apply my else stmt.

please send the else loop stmt query from my above query.

please help me.

i want to write the query in from1.cs page
Posted
Updated 28-Dec-12 3:16am
v3

1 solution

Im not sure i quite understand your question, but one thing, please please please for the sake of your coworkers or whatever poor soul may come behind you do not write your sql like that. It is a NIGHTMARE to maintain when written like what you have posted. Not saying mine is perfect either (and its not going to be for how fast i threw this together) but for your future sanity and those around you, refactor your sql.

Now im not sure i entirely understand your question but i saw some issues with your date comparison that i thought needed extra parenthesis around it in order for your query to work. I've also thrown together a sample in c# looping on the data reader where you can then pull values from your query and do whatever logic you are trying to do from there.

C#
string ConnectionString = String.Format(@"Data Source = {0};User Id={1}; password={2}; Initial Catalog = {3};",
							ConfigurationManager.AppSettings["DB_Server"],
							ConfigurationManager.AppSettings["DB_User"],
							ConfigurationManager.AppSettings["DB_Pass"],
							ConfigurationManager.AppSettings["DB_Name"]);
															
string query = string.Format(@"SELECT 
			            S.Name,
				    S.DOB,
				    S.Mobileno,
				    S.Weddingday 
			       FROM 
                                    BirthDayWish AS S 
                               WHERE S.Active <> 'D'
                               AND 
                                   year(DOB) <> '1900'
                               AND 
				   (month(DOB) = month('{0}') AND day(DOB) = day ('{0}')) 
			       OR 
				   (year(Weddingday) <> '1900' AND month(Weddingday) = month('{0}') AND day(Weddingday) = day ('{0}'))", DateTime.Now);	
							
SqlConnection connection = new SqlConnection(ConnectionString);
connection.Open();
SqlCommand queryCMD = new SqlCommand(query, connection);
SqlDataReader queryReader = queryCMD.ExecuteReader();
while (queryReader.Read())
{
	//Do Logic Here To Handle SMS
	//Could also handle WHERE Criteria in your sql here as well if you wanted
	//ex:
	/*
		if(DateTime.Now.Year != 1900)
		{
			//Send SMS
		}
	
	*/
}
 
Share this answer
 
v3

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900