Forum Replies Created

Viewing 15 posts - 61 through 75 (of 1,192 total)

  • RE: Performance of GROUP BY multiple columns

    A nice thought-provoking question!

    The answer really does depend, though. Under some conditions the first two queries got the same query plan on my system (and performed equivalently), and...

  • RE: Pivot interview questions

    This is actually an unpivot, and you could do it either with the UNPIVOT operator or with CROSS APPLY. Using the sample data you provided:

    SELECT empid,...

  • RE: Checking sort order and fixing it

    Assuming you have something in the table that identifies the task list to which each of those items belongs, identifying problem data should be as simple as doing a ROW_NUMBER...

  • RE: Trigger woes

    Heh, no worries. We've all skimmed over some important detail once or twice (no more than that, right? 🙂 )

    It would be odd for it to be a...

  • RE: Trigger woes

    The trigger mentioned in the error is not the trigger for which you posted code. 

    Could you post the definition of the trigger mentioned in the error (trg_tbl_Results_Update_SYSDateLastUpdated)?

  • RE: Persistence of function parameters

    In the first example, you're just passing the current value of a variable to the TVF, so it'll of course be the same in each query that's UNIONed in the...

  • RE: Using two "With" statements in a stored procedure

    There's just one WITH clause, and specify the options you want:

    WITH ENCRYPTION, EXECUTE AS 'RemoteLink'

    Cheers!

  • RE: How to write this query?

    The Dixie Flatline - Tuesday, March 27, 2018 11:14 AM

    Just thought I'd mention that I tried both cte tally schemes and they...

  • RE: Correlated subquery using two tables

    Please don't post the same question multiple times. It causes far more problems than it solves (it solves none, basically).

    The original thread, which already has one reply, can...

  • RE: How to write this query?

    That sort of CTE is part of a common construct to form an on-the-fly tally or numbers table.

    The specific values don't really matter; it's just generating a certain...

  • RE: How to write this query?

    To add a further tweak, nothing about the ROW_NUMBER is needed here, so there's no need to add the overhead of generating it.

    Something like this is sufficient and...

  • RE: get date by rank

    Here's another way, also using pietlinden's sample data:

    SELECT A.*, PayDate
    FROM Acct A OUTER APPLY
    (
    SELECT PayDate FROM PayDates WHERE PayDate>FixDate ORDER...

  • RE: first-in first-out profit calculation

    If I understand the requirements correctly, here's one method:

    WITH
    n   AS (SELECT N FROM (VALUES(0),(0),(0),(0),(0),(0),(0),(0),(0),(0))x(n)),
    n6   AS (SELECT n1.N FROM n n1, n n2,...

  • RE: Grouping a list of dates into date ranges

    Perhaps something like this?

    WITH CTE AS
    (
    SELECT *, grp=DATEADD(DAY,-ROW_NUMBER() OVER (PARTITION BY CargoColmn ORDER BY DateLogged ASC),DateLogged)
    FROM #MyDates
    )

    SELECT DateFrom=MIN(DateLogged), DateTo=MAX(DateLogged),CargoColmn
    FROM ...

Viewing 15 posts - 61 through 75 (of 1,192 total)