Forum Replies Created

Viewing 15 posts - 391 through 405 (of 4,085 total)

  • Reply To: Sort Alphanumeric Values in SQL Server

    You're fixing the wrong problem.  The problem here is that you have several pieces of information in one field violating first normal form.  Fix the problem at the source rather...

    J. Drew Allen
    Business Intelligence Analyst
    Philadelphia, PA

  • Reply To: Using a CASE "END AS" name within a SELECT query

    There are two solutions CTE or CROSS APPLY.

    SELECT DISTINCT
    ph.STARTDATE
    ,ph.SERIALNUMBER
    ,dc.DESTINATIONGROUP
    ,pi.PLEDGEID
    ,pi.INSTALMENTID
    ,pi.INSTALMENTSTATUS
    ,pi.DATEDUE
    ,pi.INSTALMENT
    ,gd.GADStatus
    ,ga.GIFTAID
    ,pi.INSTALMENT + ga.GIFTAID AS TOTALWITHGIFTAID
    FROMdbo.PLEDGEHEADER AS ph
    INNER JOIN dbo.PLEDGEINSTALMENT AS pi
    ON pi.PLEDGEID = ph.PLEDGEID
    LEFT OUTER JOIN dbo.GIFTAID_CURRENTDECLARATION AS gd
    ON...

    J. Drew Allen
    Business Intelligence Analyst
    Philadelphia, PA

  • Reply To: Update statement is very slow recently

    ScottPletcher wrote:

    One should always try to avoid a function on a table column being used for lookup.  Therefore, for the last JOIN, do this instead:

      LEFT...

    J. Drew Allen
    Business Intelligence Analyst
    Philadelphia, PA

  • Reply To: DELETE SQL Query

    This seems fairly straightforward.  What have you tried and where are you running into problems?

    Drew

    J. Drew Allen
    Business Intelligence Analyst
    Philadelphia, PA

  • Reply To: Update statement is very slow recently

    WITH(NOLOCK) is not a magic "go faster" code.  It reads dirty data.  You almost certainly don't want to read dirty data when making an update.

    Beyond that, there's not a whole...

    J. Drew Allen
    Business Intelligence Analyst
    Philadelphia, PA

  • Reply To: update table b if b.time falls between any of table a rows start/stop

    STOP USING CURSORS for simple updates.  A previous response showed how to rewrite your original query without using a cursor.

    SQL Server is optimized for SET-BASED operations.  Using a CURSOR prevents...

    J. Drew Allen
    Business Intelligence Analyst
    Philadelphia, PA

  • Reply To: Query to find dependencies for a stored procedure

    SSMS is doing a recursive search.  I like Redgate's SQL Dependency Tracker.

    Drew

    J. Drew Allen
    Business Intelligence Analyst
    Philadelphia, PA

  • Reply To: Date parameter

    Date fields do not have formats.  Formats are applied by the presentation layer.

    If you are storing "dates" in character fields, STOP IT!!!!! You should use the correct data type for...

    J. Drew Allen
    Business Intelligence Analyst
    Philadelphia, PA

  • Reply To: Duplicate data

    This works, but it would be much simpler with a PK field.  (I used all of the fields in place of a PK.)

    WITH standardized_mismatches AS
    (
    SELECT o.*
    , ROW_NUMBER()...

    J. Drew Allen
    Business Intelligence Analyst
    Philadelphia, PA

  • Reply To: Stored Procedure

    Steve Collins wrote:

    "most recent" is the smallest date

    English must be your second language, because that is certainly not the case.

    Drew

    J. Drew Allen
    Business Intelligence Analyst
    Philadelphia, PA

  • Reply To: Stored Procedure

    Steve Collins wrote:

    The ORDER BY entr_dt I think should be ascending.  Earlier is better?

    yrstruly wrote:

    If the scores are tied, the person who got it the most recent is shown higher.

    I assume...

    J. Drew Allen
    Business Intelligence Analyst
    Philadelphia, PA

  • Reply To: Delete from parent table question

    Guras wrote:

    I want to keep the child data but just clear out the parent  table.

    In that case, I would do a "soft" delete.  That is, I would mark the parent...

    J. Drew Allen
    Business Intelligence Analyst
    Philadelphia, PA

  • Reply To: Best way to write query that shows orders that\'ve purchased 2 specific products?

    MVDBA (Mike Vessey) wrote:

    although in your example order 789 contains 3 items, do you only want where there are 2 items? both of which are 1 and 2? or if you have...

    J. Drew Allen
    Business Intelligence Analyst
    Philadelphia, PA

  • Reply To: Stored Procedure

    When requesting help with a problem like this, you need to provide CONSUMABLE DATA and expected results.  Text tables are not CONSUMABLE.  PICTURES are not DATA.  This is how you...

    J. Drew Allen
    Business Intelligence Analyst
    Philadelphia, PA

  • Reply To: Best way to write query that shows orders that\'ve purchased 2 specific products?

    Since you didn't provide sample data IN A CONSUMABLE FORMAT, you're getting untested code.  This might perform better.

    SELECT OrderID
    FROM OrderDetails
    WHERE ProductID IN (1, 2)
    GROUP BY OrderID
    HAVING COUNT(DISTINCT...

    J. Drew Allen
    Business Intelligence Analyst
    Philadelphia, PA

Viewing 15 posts - 391 through 405 (of 4,085 total)