SNB Solutions - Baja California Software Company
Welcome Guest Search | Active Topics | Log In | Register

Tag as favorite
Getting the number of rows for todays date in MS SQL
stoian_bycovich
#1 Posted : Friday, February 26, 2010 2:50:17 PM

Rank: Administration

Medals:

Groups: Administrators
Joined: 1/2/2010
Posts: 79
Points: 10,237
Location: Cabo San Lucas

Thanks: 0 times
Was thanked: 0 time(s) in 0 post(s)
Great in this example I am going to show you how you can get the rows from sql table (lets say you want to get the number of records that your users had made). For this purpose I will call our sql table just "table" and will make a field called "PostDate" where I am going to store DateTime.Now when user makes a post and I will use this field to compare it with the T-SQL getdate() which returns SQL servers date time. Ok, The "104" argument that you can see is German date time format dd.mm.yyyy.

SELECT COUNT(*) AS [rowcounttoday] FROM table CONVERT(char,PostDate,104) = CONVERT(char,getdate(),104)

Ok let's make a use of this and bind it to a lable control for exapmle:

<asp:SqlDataSource ID="SqldataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:MyConnection %>" SelectCommand="Select Count(*) As [rowcounttoday] from posts where convert(char, PostDate, 104) = convert(char, getdate(),104)" />

<asp:DataList ID="datalist1" runat="server" DataSourceID="SqldataSource1">

<ItemTemplate>

<asp:Lable ID="lblTodaysPosts" runat="server" Text="Number of todays posts: " />

<asp:Lable ID="lblNumber" runat="server" Text='<%# Bind ("rowcounttoday")%>' />

</ItemTemplate>

</DataList>

Hope it helps

Cheers
Best regards,
Stoyan Bukovich
Executive manager
SNB Solutions

Cell.: +52 6241 616969
E-mail: s.bucovich@snb-bg.com
Web: www.snb-bg.com
Sponsor  
 
Eannouncements.net SNB Solutions Eanuncios.net

Eannouncements.net the place for your announcement.

SNB Solutions - Software and computing services company.

Eanuncios.net el lugar para su anuncio.

Users browsing this topic
Guest
Tag as favorite
Forum Jump  
You cannot post new topics in this forum.
You cannot reply to topics in this forum.
You cannot delete your posts in this forum.
You cannot edit your posts in this forum.
You cannot create polls in this forum.
You cannot vote in polls in this forum.