Click here to Skip to main content
13,291,084 members (66,760 online)
Rate this:
Please Sign up or sign in to vote.
See more:
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.
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 28-Dec-12 0:20am
Updated 28-Dec-12 4:16am

1 solution

Rate this: bad
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};",
string query = string.Format(@"SELECT 
                                    BirthDayWish AS S 
                               WHERE S.Active <> 'D'
                                   year(DOB) <> '1900'
				   (month(DOB) = month('{0}') AND day(DOB) = day ('{0}')) 
				   (year(Weddingday) <> '1900' AND month(Weddingday) = month('{0}') AND day(Weddingday) = day ('{0}'))", DateTime.Now);	
SqlConnection connection = new SqlConnection(ConnectionString);
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
		if(DateTime.Now.Year != 1900)
			//Send SMS

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

  Print Answers RSS
Top Experts
Last 24hrsThis month

Advertise | Privacy |
Web02 | 2.8.171207.1 | Last Updated 29 Dec 2012
Copyright © CodeProject, 1999-2017
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