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 2005 Forums
 Transact-SQL (2005)
 AND , BETWEEN LOGIC

Author  Topic 

jszulc
Yak Posting Veteran

66 Posts

Posted - 2009-01-07 : 16:06:16
I need help with writing a procedure to show all completed RealEstate projects ytd. This procedure does not work now.

ALTER procedure [dbo].[sp_CompletedRealEstateProjectsYTD]
as
declare @dtDate as datetime
declare @YTDStartDate as datetime
declare @CurrentDate as datetime

set @dtDate= getDate()
select @YTDStartDate = convert(char(10),dateadd(day,-1*datepart(dayofyear,@dtDate)+1,@dtDate),101)
select @CurrentDate = convert(char(10),@dtDate,101)

select * from KPITBL WHERE
STATUS = 'Completed' and [ProjectType]='RealEstate' and StatusCompletedDate between @YTDStartDate and @CurrentDate

SwePeso
Patron Saint of Lost Yaks

30421 Posts

Posted - 2009-01-07 : 16:14:31
[code]ALTER PROCEDURE dbo.sp_CompletedRealEstateProjectsYTD
AS

SET NOCOUNT ON

DECLARE @YTDStartDate DATETIME,
@NextDate DATETIME

SELECT @YTDStartDate = DATEADD(YEAR, DATEDIFF(YEAR, 0, GETDATE()), 0),
@NextDate = DATEADD(DAY, DATEDIFF(DAY, 0, GETDATE()), 1)

SELECT *
FROM KPITBL
WHERE StatusCompletedDate >= @YTDStartDate
AND StatusCompletedDate < @NextDate
AND STATUS = 'Completed'
AND [ProjectType] = 'RealEstate'[/code]


E 12°55'05.63"
N 56°04'39.26"
Go to Top of Page

jszulc
Yak Posting Veteran

66 Posts

Posted - 2009-01-07 : 17:08:11
Thank you very much, it works perfectly
Go to Top of Page
   

- Advertisement -