Click here to Skip to main content
15,896,730 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
hi!


i want to fetch the details from the table until previous day it should not fetch present system date details...
Posted
Comments
Rajesh Anuhya 12-Dec-11 5:26am    
Not Clear

SQL
SELECT * FROM myTable WHERE dateInserted <= GETDATE()-1
 
Share this answer
 
It would be helpful if you specify the column name that holds a datetime for your table records and at least mention what technique you are using to access the database, e.g. is it "T-SQL", "Stored Procedures", or Maybe it's "Linq-Sql" or seamlessly something else? That way people will give you their correct answer based on their understanding other leaving your question up for guesing, which is exactly what you have done!

Now, below is my guess:
- I assume you have a table called "Comments" and in this table you have a column called "CommentDate"
- I will give the same solution in both T-SQL and Linq-SQL

C#
DateTime endDate = DateTime.Now.AddDays(-1);//reduces the end date to yesterday
//1. T-SQL
String tsqlQuery = "SELECT * FROM Comments c WHERE c.CommentDate <='" + endDate + "';";
SqlCommand cmd = new SqlCommand();
SqlDataReader reader = cmd.ExecuteReader();
while( reader.Read() )
{
   //here are your results
}

//2. Linq-SQL
var comments = (from c in dataContext.Comments
               where c.endDate <= endDate
               select c).ToList();

foreach(Comment comment in comments)
{
   
}


That's fairly basic, i don't understand your full requirements and i couldn't expand my solution further than this;

Happy Coding,
Morgs
 
Share this answer
 

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


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