Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: C#
DOB    datetime 
WEdding datetime 
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 27-Dec-12 23:20pm
Edited 28-Dec-12 3:16am
v3

1 solution

Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

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.
 
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
		}
	
	*/
}
  Permalink  
v3

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

  Print Answers RSS
0 OriginalGriff 6,649
1 Sergey Alexandrovich Kryukov 6,270
2 CPallini 5,190
3 George Jonsson 3,574
4 Gihan Liyanage 2,522


Advertise | Privacy | Mobile
Web02 | 2.8.140916.1 | Last Updated 29 Dec 2012
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100