Forum Replies Created

Viewing 15 posts - 1,981 through 1,995 (of 3,957 total)

  • RE: Last Sunday of a month in sql

    If you don't like magic numbers, I think you can do it this way too:

    select

    a.DT,

    LastDayofMonth = dateadd(mm,datediff(mm,-1,a.DT),-1),

    LastSundayofMonth =

    dateadd(dd,(datediff(dd,'17530107',dateadd(mm,datediff(mm,-1,a.DT),-1))/7)*7,'17530107'),

    DwainsWay =

    1+dateadd(mm,datediff(mm,-1,a.DT),-1)-DATEPART(weekday, dateadd(mm,datediff(mm,-1,a.DT),-1))

    from

    (...

  • RE: tricky many to many query

    Something like this perhaps?

    DECLARE @Paths TABLE (

    INT,

    INT)

    INSERT INTO @Paths

    SELECT 1 , 2

    UNION ALL SELECT 2 , 3

    UNION ALL SELECT 3 , 4

    UNION ALL SELECT 1 , 4

    UNION...

  • RE: Count Decimal Places

    Then again, there's always some schmo that's going to come along and try to beat it.

    SELECT TestNum, Jeff=CASE

    ...

  • RE: Calculating a Moving Average

    ChrisM@Work (2/11/2013)


    Gabriel Priester wrote an article discussing the calculation of moving average. Various alternatives are covered in the discussion.

    A QU for moving averages??? :w00t: Who'da thunk it!

  • RE: Count Decimal Places

    I know I must be doing something wrong here so will somebody please check me?

    SELECT TestNum, Jeff=CASE

    WHEN...

  • RE: Calculating a Moving Average

    Try removing some of the TestNode data for ELMARA and then see if the modified query gives you what you want.

    --union

    --select '01/27/2012 05:00:00','PEACH BOTTOM','ELMARA',7

    --select '02/06/2012 05:00:00','PEACH BOTTOM','ELMARA',6

    --union

    --select '02/10/2012 05:00:00','PEACH BOTTOM','ELMARA',-41

    --union

    SELECT...

  • RE: Separate Groups by Sequential ID

    OPC.THREE was asking you to put your data into a format something like this:

    DECLARE @switches TABLE

    (ID INT IDENTITY

    ,MyDate DATETIME

    ...

  • RE: Are the posted questions getting worse?

    SQLRNNR (2/10/2013)


    L' Eomot Inversé (2/8/2013)


    Lynn Pettis (2/8/2013)


    Revenant (2/8/2013)


    Lynn Pettis (2/8/2013)


    Am I (shudder) an idiot?

    No. Is there anything that make you think you are?

    🙂

    Not really, other than having someone call me...

  • RE: Maximum Concurrent Users in a day

    Jeff Moden (2/9/2013)


    SQL Kiwi (2/9/2013)


    Kwisatz78 (2/8/2013)


    I have a table which contains login and logout times for a large set of users, and we are wanting to know how to...

  • RE: Calculating a Moving Average

    If your TestNode data contains contiguous dates (meaning no missing dates) for both source/sinks (as provided), there is no need to use the TestDate table.

    SELECT a.Sink, a.[Source], a.TimePoint, [20DayAvg]=AVG(a.Delta)

    FROM TestNode...

  • RE: TSQL Join query help

    Sean Lange (2/8/2013)


    dwain.c (2/7/2013)


    How about something like this to avoid the self-join? Uses Sean's setup data.

    SELECT Div_time, Unit_id

    ,TimeDifferenceMin=DATEDIFF(minute, MIN(Filled_Time), MAX(Filled_Time))

    FROM #Something

    GROUP BY Unit_id, Div_time

    HAVING MAX(Filled_Time)...

  • RE: Finding patterns in rows (date ordered)

    greg.bull (2/8/2013)


    2) I did hope, cunningly, that the "threat" of cursors might trigger some kind of reaction from you.

    Greg.

    :w00t::crying::-P:angry:!!!!CURSORS!!!!:w00t::crying::-P:angry:

    Grrrrr!!!!!

  • RE: Finding patterns in rows (date ordered)

    greg.bull (2/8/2013)


    OK best I can think of then is to use a calendar table to plug holes in the data - processing each staffid one by one in a supervisory...

  • RE: Catch Data between symbols in SQL

    Sean Lange (2/7/2013)


    How about using the DelimitedSplit8k? This seems to be super fast to me.

    Select Id,

    MAX(Case When ItemNumber = 1 Then Item Else '' End) As...

Viewing 15 posts - 1,981 through 1,995 (of 3,957 total)