Forum Replies Created

Viewing 15 posts - 151 through 165 (of 4,086 total)

  • Reply To: Help with calculating Percentages

    You're doing integer division, which is why you're getting 0's.  Instead of specifying 1 (integer), specify 1.0 (decimal).

    Also, you don't need the ISNULL() if you specify the CASE expression correctly.

  • This reply was modified 3 years, 7 months ago by drew.allen.

J. Drew Allen
Business Intelligence Analyst
Philadelphia, PA

  • Reply To: Retrieve records from a database table where the value of a certain column is th

    The page that you linked to contains three separate approaches to a very similar problem.  If you are having problems with one or more of those approaches, show us what...

    J. Drew Allen
    Business Intelligence Analyst
    Philadelphia, PA

  • Reply To: SELECT DISTINCT on multiple columns along with other columns

    There are basically two approaches that you can use ROW_NUMBER() and GROUP BY.

    • In the ROW_NUMBER() method, you would create a row number with a partition on your columns (Col1,...

    J. Drew Allen
    Business Intelligence Analyst
    Philadelphia, PA

  • Reply To: SQL Repeating Node

    The TYPE directive just says to return the results as XML rather than a string. TYPE Directive in FOR XML Queries

    Drew

    J. Drew Allen
    Business Intelligence Analyst
    Philadelphia, PA

  • Reply To: Get Distinct Value from each column in a Table

    A newbie replied to a decade old post.  I'm not sure you're going to get much info from the original poster.

    Drew

    J. Drew Allen
    Business Intelligence Analyst
    Philadelphia, PA

  • Reply To: How to make sure for each ID there was no records exists with text

    EVERY SINGLE TIME you post data you have to be reminded of the best way to post data.  I've come to the conclusion that you don't want to learn, you...

    J. Drew Allen
    Business Intelligence Analyst
    Philadelphia, PA

  • Reply To: Issue Extracting 2nd Level Node Data from JSON File

    related_resources is an array of JSON and you haven't supplied the index for the array.  The array is zero-based.  See the example below.

    Declare @JSON Nvarchar(max) = N'{"notes"...

    J. Drew Allen
    Business Intelligence Analyst
    Philadelphia, PA

  • Reply To: Replace function not working

    Maybe STUFF() would work better if this text is always at the beginning.

    SELECT STUFF([error], 1, CHARINDEX('Quote', [error])-1, '')

    Drew

    J. Drew Allen
    Business Intelligence Analyst
    Philadelphia, PA

  • Reply To: Islands (no gaps) - Problem solved but could this be done better?

    This produces the exact same results as your working query, but I think that the logic is simpler to follow.

    WITH TierChanges AS
    (
    SELECT ui.UserID
    ...

    J. Drew Allen
    Business Intelligence Analyst
    Philadelphia, PA

  • Reply To: SQL Query to display having only values

    Given the column naming convention, I think there might be a simpler solution than using an EAV.  This assumes that there are three sets of weights: PWT, PNT, and PTT...

    J. Drew Allen
    Business Intelligence Analyst
    Philadelphia, PA

  • Reply To: Additional records needed with Using MAX function on Most Recent Record

    I believe that the following solution will perform better.

    WITH last_visits AS
    (
    SELECT t.primarydoc
    , t.client_id
    , t.visitdoc
    , t.doc_id
    , t.visit_id
    , t.visit_date
    ...

    J. Drew Allen
    Business Intelligence Analyst
    Philadelphia, PA

  • Reply To: Find value of next row upon condition

    Jonathan AC Roberts wrote:

    Create some test data:

    DROP TABLE IF EXISTS TestTable
    GO
    CREATE TABLE TestTable
    (
    NoSeqTrt INT,
    NoSeqIti INT,
    idPointsrv INT
    )
    ;
    GO
    -- Populate...

    J. Drew Allen
    Business Intelligence Analyst
    Philadelphia, PA

  • Reply To: IF EXISTS + temp table or CTE

    A CTE is part of data manipulation language (DML), specifically an INSERT, UPDATE, SELECT, or DELETE statement.  An IF...THEN...ELSE is a workflow statement.  You CANNOT have a workflow statement in...

    J. Drew Allen
    Business Intelligence Analyst
    Philadelphia, PA

  • Reply To: Return a set of rows between 2 values (multiple times)

    Thom A wrote:

    Jeff Moden wrote:

    Thom A wrote:

    So where do these linked integers come from? Why, for example, is 1 linked to 1, 2, and 3, but the numbers 8 to 14 only linked...

    J. Drew Allen
    Business Intelligence Analyst
    Philadelphia, PA

  • Reply To: Update records using previous row and calculated value of current row.

    learnsql wrote:

    Hi Jeff,

    Thanks for the response. The Window functions cannot be used in update statements directly, so I used a different technique, whereby I had partitioned the data of unique...

    J. Drew Allen
    Business Intelligence Analyst
    Philadelphia, PA

  • Viewing 15 posts - 151 through 165 (of 4,086 total)