Forum Replies Created

Viewing 7 posts - 1 through 7 (of 7 total)

  • RE: Query to get Last month's Data

    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

  • RE: Best way to Calculate Human Age from a Birthdate

    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...

  • RE: ROUND() function doesn't round properly

    DECLARE @test-2 TABLE (

    EmpName VARCHAR(40) ,

    ...

  • RE: Script all indexes as CREATE INDEX statements

    SELECT ' CREATE ' +

    CASE

    WHEN I.is_unique = 1 THEN '...

  • RE: Pipe Symbol as Column delimiter

    --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 *...

  • RE: Previous week date range

    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

  • RE: T-SQL to list all users and their permission for all databases of a server?

    --Audit User Permissions

    SELECT [UserName] = ulogin.[name],

    [UserType] = CASE princ.[type]

    ...

Viewing 7 posts - 1 through 7 (of 7 total)