Forum Replies Created

Viewing 15 posts - 376 through 390 (of 4,085 total)

  • Reply To: Remove everything between parenthesis

    shahgols wrote:

    Thank you all, appreciate it.  I forgot to mention that the number of open/close parenthesis can vary.  I'll see if I can work off your solutions to make that...

    J. Drew Allen
    Business Intelligence Analyst
    Philadelphia, PA

  • Reply To: Remove everything between parenthesis

    Unfortunately, Jonathan's approach fails when you have nested parens.  This approach works even with nested parens.

    DECLARE @item VARCHAR(150) = 'All I want (for Christmas (or maybe my...

    J. Drew Allen
    Business Intelligence Analyst
    Philadelphia, PA

  • Reply To: T SQL While Loop - Into a Temp table for final output

    You never populate your @Output table.

    Also, single-row WHILE loops tend to perform worse than CURSORs.  I see nothing in your code that would require to you process a single row...

    J. Drew Allen
    Business Intelligence Analyst
    Philadelphia, PA

  • Reply To: Getting Min and Max dates by segment for continuous enrollment

    This is a variation on packing intervals.  This approach assumes that there are no gaps.  You need a slightly different approach if gaps are possible.

    WITH status_starts AS
    (
    SELECT...

    J. Drew Allen
    Business Intelligence Analyst
    Philadelphia, PA

  • Reply To: Help on excluding dates

    You cannot define a CTE inside of a subquery as you are trying to do.  The correct syntax is more like the following, although it's untested because you haven't supplied...

    J. Drew Allen
    Business Intelligence Analyst
    Philadelphia, PA

  • Reply To: Are the posted questions getting worse?

    Steve Jones - SSC Editor wrote:

    I wonder if more of us ought to be using UTC or at least datetimeoffset for applications. There are more and more that are crossing time zones and it...

    J. Drew Allen
    Business Intelligence Analyst
    Philadelphia, PA

  • Reply To: Help on excluding dates

    This appears to perform better, because it only requires reading the table once.  You should probably perform a more thorough analysis with a larger data set.

    WITH window...

    J. Drew Allen
    Business Intelligence Analyst
    Philadelphia, PA

  • Reply To: * to 1

    The SELECT statement is ignored.  This can be seen by running the following query, where the query runs without producing a "divide by zero" error.

    IF EXISTS (...

    J. Drew Allen
    Business Intelligence Analyst
    Philadelphia, PA

  • Reply To: simple insert statement issues

    'getdate()' is a string and is not a valid date.

    Drew

    J. Drew Allen
    Business Intelligence Analyst
    Philadelphia, PA

  • Reply To: Are the posted questions getting worse?

    Thom A wrote:

    It seems that SE have a Code of Conduct change coming, which many of the moderators had concerns over. One moderator as a result of them disagreeing with the...

    J. Drew Allen
    Business Intelligence Analyst
    Philadelphia, PA

  • Reply To: Compare contents of two XML files

    You also need to specify what you mean by "equal or different".  XML files can contain exactly the same information, but have a slightly different layout.  Are they equal because...

    J. Drew Allen
    Business Intelligence Analyst
    Philadelphia, PA

  • Reply To: Which items can be built (do we have enough product for)?

    I believe that this is a variation on the bin packing problem.  I think it's possible to solve without using a cursor, but I would need sample data and expected...

    J. Drew Allen
    Business Intelligence Analyst
    Philadelphia, PA

  • Reply To: Dynamic Query Needed

    Also, you should ALWAYS use QUOTENAME() to insert brackets.  Doing it the way you did opens you up to SQL injection.

    Drew

    J. Drew Allen
    Business Intelligence Analyst
    Philadelphia, PA

  • Reply To: Update table rows within 5 mins of a table rows datetime

    This is a packing intervals problem.  Here is a solution that only requires one scan of the table.

    ;
    WITH intervals AS
    (
    SELECT
    a.rowId
    ,a.myDatetime
    ,a.myCount
    ,a.invalid
    ,CASE WHEN LAG(a.myDatetime, 1, '1900-01-01')OVER(ORDER BY a.myDateTime) <...

    J. Drew Allen
    Business Intelligence Analyst
    Philadelphia, PA

  • Reply To: Help with SQL Query to Exclude Values

    John Mitchell-245523 wrote:

    Try this as well.

    WITH Partitioned AS (
    SELECT
    memb_MembershipID
    ,memb_MemberID
    ,memb_type
    ,MIN(memb_type) OVER (PARTITION BY memb_MemberID) AS MinMemb
    ,MAX(memb_type) OVER (PARTITION BY memb_MemberID) AS MaxMemb
    FROM dbo.Members
    )
    SELECT
    memb_MembershipID
    ,memb_MemberID
    ,memb_type
    FROM Partitioned
    WHERE MinMemb <> 'Tier 1'
    AND...

    J. Drew Allen
    Business Intelligence Analyst
    Philadelphia, PA

Viewing 15 posts - 376 through 390 (of 4,085 total)