Forum Replies Created

Viewing 15 posts - 1 through 15 (of 125 total)

  • RE: Need assistance with merging duplicate records based on dates in two different fields

    From what I can see, you're looking for the earliest start date and latest d date?


    SELECT    A.[From],
            A.[To],
            A.Company,
            A.Vehicle,
            MIN(A.StartDate),
            MAX(A.EndDate)
    FROM    dbo.ExampleTable AS A
    GROUP    BY...

  • RE: EXECUTE AS and REVERT

    Thom A - Tuesday, January 31, 2017 8:32 AM

    The context of the whole SP will be run as WindowsUsers1 when declaring WITH...

  • RE: Call SQL agent job Via Stored Procedure

    I had this snippet I used a while back, which may be of use to you. It gets the ID of the job based on the name and then starts...

  • RE: RAISERROR - Stored Proc wrapped in sqlAgent job

    I had similar issues myself a few weeks back (SQL SERVER 2008).

    Data Flow task would run a stored procedure as the source, get a row count and then create a...

  • RE: Using Mod to Generate Work Shifts

    Could possibly remove the case

    CREATE FUNCTION [dbo].[ShiftCalc]

    (

    @ShiftTime DATETIME,

    @ShiftStart DATETIME,

    @NumOfShifts TINYINT

    )

    RETURNS TABLE WITH SCHEMABINDING

    AS

    RETURN

    SELECT

    OnShift = CHAR(ABS(DATEDIFF(DAY,@ShiftStart,DATEADD(HOUR,-DATEPART(HOUR,@ShiftStart), @ShiftTime))) % @NumOfShifts + 65);

    DECLARE @ShiftAStart DATETIME = '2006-01-01T07:00:00';

    SELECTD.Incident,

    CA1.OnShift

    FROM(

    VALUES(CAST('2006-01-01T07:00:00' AS DATETIME)),

    ('2006-01-01T17:00:00'),

    ('2006-01-02T06:00:00'),

    ('2006-01-02T07:00:00'),

    ('2006-01-02T23:00:00'),

    ('2006-01-03T07:00:00'),

    ('2006-01-03T09:00:00'),

    ('2006-01-04T07:00:00')

    ) AS D(Incident)

    CROSS

    APPLYdbo.ShiftCalc(D.Incident,@ShiftAStart,3) AS CA1;

  • RE: Adding zeros into date column

    From what you're saying you want to replace all with 0s..

    UPDATE TestTable_1

    set datecolumn = '0000-00-00';

  • RE: TSQL, Percentile with NTILE(100) for less then 100 obesrvations, how to display on 100 scale?

    Does this do what you're after? Checks if there are less than 100 observations and then multiples the rank by a factor if needed

    USE tempdb;

    WITH CTE

    AS

    (

    SELECT 100 Cust_ID ,...

  • RE: How show only first friday of every month

    The idea was to not make it dependent on the DATEFIRST setting and the basis there was no calendar table. Using DATEDIFF(DAY,0,@StartDate)%7 you know that 0 will always be the...

  • RE: How show only first friday of every month

    Alvin Ramard (7/3/2015)


    Phil Parkin (7/3/2015)


    Alvin Ramard (7/3/2015)


    Why are you trying to make everything so complicated?

    Avril Lavigne?

    She would sound better right now. 😛

    Why? Boredom! Not sure if Avril sings about that...

  • RE: How show only first friday of every month

    Alvin Ramard (7/2/2015)


    vipin_jha123 (7/2/2015)


    Hi,

    I am having one requirement where I want to show only first Friday of every month of 2014,2015 and 2016 year.

    Please suggest me the logic

    Regards,

    Vipin jha

    Try this...

  • RE: How show only first friday of every month

    sgmunson (7/2/2015)


    vipin_jha123 (7/2/2015)


    Using SQL Qury.

    Here's a query that converts from numeric values, although if you want to just generate this data independent of other table values, then you could change...

  • RE: How to merge two tables data on behalf of id in comma separated manner in sql server 2012

    This should work:

    DECLARE @Chuff TABLE

    (

    Sub_Cat_ID INT NOT NULL,

    BSNS_IDINT NOT NULL,

    BSBS_PRFX VARCHAR(10) NOT NULL,

    DO_ID INT NOT NULL

    );

    INSERT INTO @Chuff (Sub_Cat_ID,BSNS_ID,BSBS_PRFX,DO_ID)

    VALUES (13,16,'cntcr',3),

    (11,16,'cntcr',3),

    (2058,1,'cntcr',3);

    DECLARE @Chuff2 TABLE

    (

    seq INT NOT NULL,

    Descr VARCHAR(25) NOT NULL

    );

    INSERT INTO @Chuff2...

  • RE: How show only first friday of every month

    A calendar table would be good here, although I think the code below should also do the job

    DECLARE@StartDayDATETIME = '20140101',

    @EndDayDATETIME = '20161231';

    WITH DateBase (DT,RN)

    AS

    (

    SELECTA.DT,

    ROW_NUMBER() OVER (PARTITION BY YEAR(A.DT),MONTH(A.DT) ORDER BY...

  • RE: need help on Scalar value Function

    Here's a start:

    SET NOCOUNT ON

    CREATE TABLE dbo.pf

    (

    codigo int not null PRIMARY KEY CLUSTERED,

    pfstamp CHAR(1) not null

    );

    CREATE TABLE dbo.pfu

    (

    pfstamp CHAR(1) not null PRIMARY KEY CLUSTERED

    );

    INSERT INTO dbo.pf (codigo,pfstamp)

    VALUES (1,'A'),

    (2,'B'),

    (4,'C'),

    (10,''),

    (11,'E'),

    (13,'F');

    INSERT INTO dbo.pfu...

  • RE: need help on Scalar value Function

    Hi Luis,

    Have you looked at the possible performance improvements of converting this into an inline table valued function (iTVF)?

Viewing 15 posts - 1 through 15 (of 125 total)