Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
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 1-Jan-13 0:15am
Edited 1-Jan-13 0:32am
v2
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

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.
  Permalink  
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 2

Lets simplify your query a little:
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
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:
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:
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:
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.
  Permalink  

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

  Print Answers RSS
Your Filters
Interested
Ignored
     
0 Shai Vashdi 1,518
1 Tadit Dash 350
2 Manas Bhardwaj 319
3 Sergey Alexandrovich Kryukov 250
4 Peter Leow 245
0 Sergey Alexandrovich Kryukov 9,530
1 OriginalGriff 5,716
2 Peter Leow 4,320
3 Maciej Los 3,540
4 Abhinav S 3,373


Advertise | Privacy | Mobile
Web03 | 2.8.140415.2 | Last Updated 1 Jan 2013
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Use
Layout: fixed | fluid