Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 Counting records

Author  Topic 

shajimanjeri
Posting Yak Master

179 Posts

Posted - 2007-05-29 : 03:58:01

I have a table with three fileds
1 - SmsTime (datatype = datetime)
2 - MsgCnt (datatype = int)
3 - Message (datatype = varchar)

Here MsgCnt means it will give the number of sms part (70 charector is equal to One SMS).
So in each row MsgCnt may be vary. Some time it may be 1 or 3 or 5 or 2 etc.
Now here I need to count how many MsgCnt is received on Today. Its not to count the rows but counting the MsgCnt fild value.
Is there any sql way to find it.

Plesase help me!

harsh_athalye
Master Smack Fu Yak Hacker

5581 Posts

Posted - 2007-05-29 : 04:02:28
[code]Select sum(MsgCnt)
From Table
Where SmsTime = getdate()[/code]

Harsh Athalye
India.
"The IMPOSSIBLE is often UNTRIED"
Go to Top of Page

khtan
In (Som, Ni, Yak)

17689 Posts

Posted - 2007-05-29 : 04:10:03
Harsh,

SmsTime = getdate() ?




KH

Go to Top of Page

shajimanjeri
Posting Yak Master

179 Posts

Posted - 2007-05-29 : 04:26:41

Thanks harsh_athalye,

Its working fine.


quote:
Originally posted by harsh_athalye

Select sum(MsgCnt)
From Table
Where SmsTime = getdate()


Harsh Athalye
India.
"The IMPOSSIBLE is often UNTRIED"

Go to Top of Page

khtan
In (Som, Ni, Yak)

17689 Posts

Posted - 2007-05-29 : 04:31:40
quote:
Originally posted by shajimanjeri


Thanks harsh_athalye,

Its working fine.


quote:
Originally posted by harsh_athalye

Select sum(MsgCnt)
From Table
Where SmsTime = getdate()


Harsh Athalye
India.
"The IMPOSSIBLE is often UNTRIED"





Are you sure you are getting any result with that ? getdate() will return the current date and time. How can you get any result with SmsTime = current date & time ?


Select sum(MsgCnt)
From Table
Where SmsTime = dateadd(day, datediff(day, 0, getdate()), 0)



KH

Go to Top of Page

shajimanjeri
Posting Yak Master

179 Posts

Posted - 2007-05-29 : 09:31:31

That I did some modifications..

regards
Go to Top of Page

khtan
In (Som, Ni, Yak)

17689 Posts

Posted - 2007-05-29 : 09:38:20
quote:
Originally posted by shajimanjeri


That I did some modifications..

regards



Good for you


KH

Go to Top of Page

harsh_athalye
Master Smack Fu Yak Hacker

5581 Posts

Posted - 2007-05-29 : 09:47:05
quote:
Originally posted by shajimanjeri


That I did some modifications..

regards




By modifications, you don't mean you used CONVERT() to truncate time part, do you?

Harsh Athalye
India.
"The IMPOSSIBLE is often UNTRIED"
Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2007-05-29 : 23:55:43
<<
By modifications, you don't mean you used CONVERT() to truncate time part, do you?
>>

Most probably yes

Madhivanan

Failing to plan is Planning to fail
Go to Top of Page
   

- Advertisement -