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
 SQL Server 2008 Forums
 Transact-SQL (2008)
 How can I write a query make the selection

Author  Topic 

anupalavila
Yak Posting Veteran

56 Posts

Posted - 2015-01-11 : 06:36:48
I have a table named activity with fields activityId,activitydate. How can I write a query to select activityId from the table between two dates in such a way that it returns values as a single row and if there is no activityId for a date in a month it should be 0

ie.

activityId activitydate
15 2015-01-01 00:00:00.000
16 2015-01-03 00:00:00.000
17 2015-01-04 00:00:00.000
18 2015-01-06 00:00:00.000
19 2015-01-10 00:00:00.000
20 2015-01-12 00:00:00.000

it show return the values like

15 0 16 17 0 18 0 0 0 10 0 20

Thanks and Regards
Anu Palavila

gbritton
Master Smack Fu Yak Hacker

2780 Posts

Posted - 2015-01-11 : 08:23:57
what have you tried so far? Post the query that you have worked up.
Go to Top of Page
   

- Advertisement -