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
 Creating a view with Declare statement

Author  Topic 

masterdineen
Aged Yak Warrior

550 Posts

Posted - 2010-11-19 : 08:56:12
i am trying to create a view using a couple of variables.

am i aloud to do this? OR Is the code wrong somewhere?

-------------------------------------------------------------------
Create View Monthly_stats (Category, Per_month) as

declare @FirstDay datetime
SELECT @FirstDay = ( SELECT DATEADD(month,datediff(month,0,getdate())-1,0))


declare @LastDay datetime
SELECT @LastDay = ( select DATEADD(month,datediff(month,0,getdate()),0)-1 )


select'New members in Month', count (individual.individual_ref)
from individual WITH (NOLOCK) , member
where member.join_date BETWEEN DATEADD(DAY, DATEDIFF(DAY, 0, @firstday), 0) AND DATEADD(DAY, DATEDIFF(DAY, 0, @lastday), 0)
and member.individual_ref = individual.individual_ref
and member.grad_date BETWEEN DATEADD(DAY, DATEDIFF(DAY, 0, @firstday), 0) AND DATEADD(DAY, DATEDIFF(DAY, 0, @lastday), 0)
and member.member_status = 33
----------------------------------------------------------------------


kind regards

Rob

MCTS / MCITP certified

masterdineen
Aged Yak Warrior

550 Posts

Posted - 2010-11-19 : 09:05:42
Its ok, no worries.

I need to create couple of functions
Go to Top of Page
   

- Advertisement -