Click here to Skip to main content
15,886,093 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
C#
Sql = "select s.Name,s.DOB,s.Mobileno,s.Weddingday from BirthDayWish s where s.Active <> 'D'";
Sql = Sql + " and (month(DOB) = month('"+ Convert.ToDateTime(CurDate) + "') and day(DOB) = day ('" + Convert.ToDateTime(CurDate) + "'))";

Sql = Sql + " or (month(Weddingday) = month('" + Convert.ToDateTime(CurDate) + "')  and  day(Weddingday) = day ('" + Convert.ToDateTime(CurDate) + "'))";


in the above query condition day and month fall that year birthdaysms be sent
and also day and month fall that year wedding sms be sent.

it is not conditon both day and month fall of birthday and wedding need not be like that.

Database column as follows;

name      DOB          Mobileno       weddingday

Ramesh    11/12/2013   9840576895      1/1/2035.
          (MM/DD/YYYY)                (MM/DD/YYYY)


in that when i send sms only wedding day sms only to be send.

but when i send sms to this number both birthday and wedding day sms has sent at a time.

because in birthday 11/12/2013 i send sms on today(1.1.2013) to this number(9840576895) only birthdaay falls on 11 dec 2013.

but birthday sms sent why.

only wedding sms to be send.

from the above query wat is the problem help me.

[edit]Code block added - OriginalGriff[/edit]
Posted
Updated 1-Jan-13 0:32am
v2

You should split your code into manageable and (more importantly) testable components. You are using the expression Convert.ToDateTime(CurDate) four times, but nowhere are you checking its result. Are you sure that CurDate is a valid date string? You should do this conversion before you start building your SQL statement so you know it is valid, and you can then easily extract the day, month and year from it. I am assuming that the dates stored in your database are stored as SQL Date or DateTime types. You should also use proper parameterised queries, rather than concatenated strings, so you can check all values at each step.
 
Share this answer
 
Lets simplify your query a little:
C#
Sql = "select s.Name,s.DOB,s.Mobileno,s.Weddingday from BirthDayWish s where s.Active <> 'D'";
Sql = Sql + " and (month(DOB) = month('"+ Convert.ToDateTime(CurDate) + "') and day(DOB) = day ('" + Convert.ToDateTime(CurDate) + "'))";

Sql = Sql + " or (month(Weddingday) = month('" + Convert.ToDateTime(CurDate) + "')  and  day(Weddingday) = day ('" + Convert.ToDateTime(CurDate) + "'))";
Becomes
SQL
select s.Name,s.DOB,s.Mobileno,s.Weddingday from BirthDayWish s where s.Active <> 'D'
 and (month(DOB) = month('2013-01-01') and day(DOB) = day ('2013-01-01'))
 or (month(Weddingday) = month('2013-01-01')  and  day(Weddingday) = day ('2013-01-01'))
Which becomes:
SQL
select s.Name,s.DOB,s.Mobileno,s.Weddingday from BirthDayWish s 
where s.Active <> 'D'
      and (month(DOB) = 1 and day(DOB) = 1)
      or (month(Weddingday) = 1 and  day(Weddingday) = 1)
And to make it even easier, I'll rewrite it as:
SQL
select s.Name,s.DOB,s.Mobileno,s.Weddingday from BirthDayWish s
where activeEqualsD and DOBMatches or WeddingdayMatches
Now, AND has precedence over OR, so that will be evaluated as:
SQL
select s.Name,s.DOB,s.Mobileno,s.Weddingday from BirthDayWish s
where (activeEqualsD and DOBMatches) or WeddingdayMatches
Which probably isn't what you want!
I'm not exactly sure what you are trying to do here - since the statement will return data based on either condition and I have no idea about your code which uses the data - but I strongly suggest that you work out exactly what you want in a similar way to the above, reversed, and use brackets to ensure execution order and priority.
 
Share this answer
 

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