TonyReba
asked on
How to Use Top Date in asp.net
I am building a web app, where the requirement is to make a form in which admin will be adidng information 3 times a day and the front user willl be reading from this Gridview. I was going to use only one Gridview with update fields, but they want to run a report every month will all entered ata
So I build a separate page for user and admin, and thought i used insert command , plus a timestamp fiedl, so the idea is to pull only the data entered on that same day they are opening the document, in other words only view the last update data not the whole data from the table?
Much help is appreciated
So I build a separate page for user and admin, and thought i used insert command , plus a timestamp fiedl, so the idea is to pull only the data entered on that same day they are opening the document, in other words only view the last update data not the whole data from the table?
Much help is appreciated
ASKER
actually my table looks like this
Id, DateTime, Col1, COl2 Col3, Col4
So it will be populated everyday , and I am trying to find the way to pull all columns but only the latest values (could be 10 values) on the day they are opening the Read only GridView, any more suggestions....
Thanks
Id, DateTime, Col1, COl2 Col3, Col4
So it will be populated everyday , and I am trying to find the way to pull all columns but only the latest values (could be 10 values) on the day they are opening the Read only GridView, any more suggestions....
Thanks
select TOP 10 * from tablename
order by DateTime
order by DateTime
ASKER
Can I use top without specifyng the number of records? 10 was only a say, but I could be any number of rows inserted on a day and the system must pull all of that day
e.g.
03/03/2011 value1 value2 value3NO
03/03/2011 value1 value2 value3NO
03/03/2011 value1 value2 value3NO
03/04/2011 value1 value2 value3 YES
e.g.
03/03/2011 value1 value2 value3NO
03/03/2011 value1 value2 value3NO
03/03/2011 value1 value2 value3NO
03/04/2011 value1 value2 value3 YES
nope,
top has to be used with some number.
Instead you can specific the current date which will pull up everything for that particular day.
top has to be used with some number.
Instead you can specific the current date which will pull up everything for that particular day.
ideally,
select * from tablename
WHERE DATEDIFF(day, tablename.datetime_col, GETDATE()) = 0
should do the job for you.
Cheers!
select * from tablename
WHERE DATEDIFF(day, tablename.datetime_col, GETDATE()) = 0
should do the job for you.
Cheers!
ASKER
so only select where date currentdate()??
how do i syntax this?
how do i syntax this?
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
great will try tomorrow, so, in this case should I stick with date only or date and time to make it more accurate? how would this be?
this is the code that feeds my date time column in the database
dateLabel.Text = DateTime.Now.ToString("ddd d, dd MMMM yyyy HH:mm");
this is the code that feeds my date time column in the database
dateLabel.Text = DateTime.Now.ToString("ddd
well if you put in date it will start from very first millisecond of that day till the latest record you have for that date
ASKER
oh one more concern, so the admin will be updating, lets say like a hotel, that you need to show available rooms, so if room status was occupied , and the latest status is available I want only show that status,,,,,, sorry I totally forgot this, so I am thinking a mix of Top and Date statement??
ASKER
select TOP 1 * from tablename
WHERE DATEDIFF(day, tablename.datetime_col, GETDATE()) = 0
order by tablename.datetime_col DESC
????
WHERE DATEDIFF(day, tablename.datetime_col, GETDATE()) = 0
order by tablename.datetime_col DESC
????
I didnt get you this comment
---------------
oh one more concern, so the admin will be updating, lets say like a hotel, that you need to show available rooms, so if room status was occupied , and the latest status is available I want only show that status,,,,,, sorry I totally forgot this, so I am thinking a mix of Top and Date statement??
----------------
---------------
oh one more concern, so the admin will be updating, lets say like a hotel, that you need to show available rooms, so if room status was occupied , and the latest status is available I want only show that status,,,,,, sorry I totally forgot this, so I am thinking a mix of Top and Date statement??
----------------
ASKER
There is two pages on the site, one for users , and one for administrator
the admin will be entering the room and the availability several times a day, so the users should see only the last entered information for each room, (status).
Also this have to show the data for that day , since the room had other statuses a day before ,,,,
the admin will be entering the room and the availability several times a day, so the users should see only the last entered information for each room, (status).
Also this have to show the data for that day , since the room had other statuses a day before ,,,,
select TOP 1 * from tablename
order by timestamp_col DESC
this will give you only 1 record with the very latest time in your timestamp column
Cheers!