Viewing 7 posts - 1 through 7 (of 7 total)
DECLARE @PreviousMonthStart DATETIME
DECLARE @PreviousMonthEnd DATETIME
SET @PreviousMonthStart = DATEADD(m,DATEDIFF(m,0,GETDATE())-1,0)
SET @PreviousMonthEnd = DATEADD(ms,-2,DATEADD(month, DATEDIFF(month, 0, GETDATE()), 0))
PRINT @PreviousMonthStart
PRINT @PreviousMonthEnd
SELECT * FROM MyTable
WHERE MyDate >= @PreviousMonthStart
AND MyDate < @PreviousMonthEnd
April 20, 2016 at 9:10 am
USE [livedb];
GO
SET ANSI_NULLS ON;
GO
SET QUOTED_IDENTIFIER ON;
GO
CREATE FUNCTION dbo.GetAge
(@DOB DATETIME,
@ToDate DATETIME
)
RETURNSSMALLINT
AS
BEGIN
DECLARE@Diff SMALLINT,
@F DATETIME,
@T DATETIME
SELECT@Diff = DATEDIFF(month, @DOB, @ToDate) / 12,
@F = DATEADD(year, 2000...
April 15, 2016 at 4:38 pm
April 15, 2016 at 2:24 pm
SELECT ' CREATE ' +
CASE
WHEN I.is_unique = 1 THEN '...
February 21, 2014 at 9:57 am
--Generate BCP DOS command to export pipe delimited data.
DECLARE @BCPCommandString VARCHAR(8000)
DECLARE @FilePath VARCHAR(1000)
DECLARE @FileName VARCHAR(1000)
DECLARE @SPName VARCHAR(1000)
DECLARE @ServerName VARCHAR(1000)
DECLARE @tSQL VARCHAR(1000)
SET @ServerName = 'myServer'
SET @tSQL = 'Select top 10 *...
March 8, 2013 at 11:55 am
select DATEADD(wk, DATEDIFF(wk,0,GETDATE()), 0) MondayOfCurrentWeek
select DATEADD(day, -7 ,DATEADD(wk, DATEDIFF(wk,0,GETDATE()), 0)) LastMondayStart
select DateAdd(ms,-3,(DATEADD(day, -6 ,DATEADD(wk, DATEDIFF(wk,0,GETDATE()), 0)))) LastMondayEnd
select DATEADD(day, -3 ,DATEADD(wk, DATEDIFF(wk,0,GETDATE()), 0)) LastFridayStart
select DateAdd(ms,-3,(DATEADD(day, -2 ,DATEADD(wk, DATEDIFF(wk,0,GETDATE()), 0)))) LastFridayEnd
January 14, 2013 at 11:01 am
--Audit User Permissions
SELECT [UserName] = ulogin.[name],
[UserType] = CASE princ.[type]
...
December 7, 2012 at 10:16 am
Viewing 7 posts - 1 through 7 (of 7 total)