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
 query by count help

Author  Topic 

megazi
Starting Member

6 Posts

Posted - 2013-12-30 : 19:35:44
Hi

i'm new for SQL and help. Below my example for my table

created_date | C_Message | C_Message_Status
---------------------------------------------
2013-12-29 | OUTBOUND | PROCESSED
2013-12-28 | VDA | NEW
2013-12-27 | OUTBOUND | PROCESSED
2013-12-27 | OUTBOUND | PROCESSED
2013-12-26 | VDA | PROCESSED

my question is
1. how to query total "OUTBOUND" sort by date from table c_Message
2. query for created_date "2013-12-29" total "OUTBOUND" was "PROCESSED"

khtan
In (Som, Ni, Yak)

17689 Posts

Posted - 2013-12-30 : 20:50:37
1. you want Total Outbound by date ?

2.

SELECT *
FROM yourtable
WHERE created_date = '2013-12-29'
AND C_Message = 'OUTBOUND'
AND C_Message_Status = 'PROCESSED'



KH
[spoiler]Time is always against us[/spoiler]

Go to Top of Page

megazi
Starting Member

6 Posts

Posted - 2013-12-30 : 21:19:58
quote:
Originally posted by khtan

1. you want Total Outbound by date ?

2.

SELECT *
FROM yourtable
WHERE created_date = '2013-12-29'
AND C_Message = 'OUTBOUND'
AND C_Message_Status = 'PROCESSED'



KH
[spoiler]Time is always against us[/spoiler]





hi

this query will showed the table without total count of outbound by date.

Go to Top of Page

khtan
In (Som, Ni, Yak)

17689 Posts

Posted - 2013-12-30 : 21:25:19
so what do you want ? show us the required result


KH
[spoiler]Time is always against us[/spoiler]

Go to Top of Page

megazi
Starting Member

6 Posts

Posted - 2013-12-30 : 21:56:05
example the query showed

total count "2" "outbound" "processed" on 2013-12-27
Go to Top of Page

khtan
In (Som, Ni, Yak)

17689 Posts

Posted - 2013-12-30 : 22:04:43
add remove any WHERE condition to your requirement

SELECT created_date, C_Message, C_Message_Status, count(*) as [total count]
FROM yourtable
WHERE C_Message = 'OUTBOUND'
AND C_Message_Status = 'PROCESSED'
AND created_date = '2013-12-29'
GROUP BY created_date, C_Message, C_Message_Status



KH
[spoiler]Time is always against us[/spoiler]

Go to Top of Page

megazi
Starting Member

6 Posts

Posted - 2013-12-30 : 23:05:39

[URL=http://imageshack.us/photo/my-images/202/4ud6.jpg/][/URL]

Uploaded with [URL=http://imageshack.us]ImageShack.us[/URL]

Hi

Referring the screenshot i execute the query but no data been display?
Go to Top of Page

khtan
In (Som, Ni, Yak)

17689 Posts

Posted - 2013-12-30 : 23:18:59
change to

SELECT DATEADD(DAY, DATEDIFF(DAY, 0, CREATED_DATE_TIME), 0), C_MESSAGE_DIRECTION_ID, . . .
FROM ...
WHERE CREATED_DATE_TIME >= '2013-05-10'
AND CREATED_DATE_TIME < '2013-05-11'
GROUP BY DATEADD(DAY, DATEDIFF(DAY, 0, CREATED_DATE_TIME), 0), C_MESSAGE_DIRECTION_ID, ...



KH
[spoiler]Time is always against us[/spoiler]

Go to Top of Page

megazi
Starting Member

6 Posts

Posted - 2013-12-31 : 00:48:48
Hi

its work perfectly for me. Thanks
Go to Top of Page
   

- Advertisement -