Forum Replies Created

Viewing 15 posts - 2,821 through 2,835 (of 4,085 total)

  • RE: Select Latest record by comparing 2 tables.

    I suspect that this will perform much better than having a second CTE and a join.

    WITH Combined AS (

    SELECT Timestampcol, <other columns>, 'Table1' AS TableName

    FROM Table1

    UNION ALL

    SELECT Timestampcol, <other columns>,...

    J. Drew Allen
    Business Intelligence Analyst
    Philadelphia, PA

  • RE: Query result with a value condition

    Try the following.

    WITH orders AS (

    SELECT o.OrdID, o.OrdDt, o.CustID, o.MtchID, p.Price, p.OrdLoc, ROW_NUMBER() OVER(PARTITION BY o.OrdID ORDER BY p.OrdLoc) AS rn, MAX(p.OrdLoc) OVER(PARTITION BY o.OrdID) AS MaxLoc

    FROM #Ord o

    INNER JOIN...

    J. Drew Allen
    Business Intelligence Analyst
    Philadelphia, PA

  • RE: Inserting data from file

    You're going to need to be a lot more specific. I suggest you start by reading Forum Etiquette: How to post data/code on a forum to get the best...

    J. Drew Allen
    Business Intelligence Analyst
    Philadelphia, PA

  • RE: SQL Issue with minutes represented as decimals ie. 30mins = .30 not .5 ?!!

    jez.omahony (2/2/2016)


    My problem is that in the source system, time is entered in terms of .3 is 30 mins and .15 as 15 mins... but amazingly enough .12 is actually...

    J. Drew Allen
    Business Intelligence Analyst
    Philadelphia, PA

  • RE: Query Help

    Change your criteria to MEETING_TYPE IN ('PADA', 'TSM'), then GROUP BY your parent info, HAVING COUNT(DISTINCT MEETING_TYPE) = 2

    Drew

    J. Drew Allen
    Business Intelligence Analyst
    Philadelphia, PA

  • RE: Bulk Insert XML...help

    There are two basic approaches you can use:

    1) Use XMLNAMESPACES

    2) Use a wild card for the namespace.

    Drew

    J. Drew Allen
    Business Intelligence Analyst
    Philadelphia, PA

  • RE: How to get records batch wise?

    Here is another solution that uses new functionality specifically for paging that was introduced in SQL 2012.

    DECLARE @pg_num INT = 1,

    @pg_size INT = 100

    SELECT [USERLOGIN]

    ,[USERFIRSTNAME]

    ,[USERLASTNAME]

    ,[ACTIVETODATE]

    ,[ACTIVATED]

    ,[DEACTIVATED]

    ,[USERID]

    FROM

    ORDER BY USERID

    OFFSET (@pg_num -...

    J. Drew Allen
    Business Intelligence Analyst
    Philadelphia, PA

  • RE: Cumulative Balance calculation

    J Livingston SQL (1/21/2016)


    here is a start

    https://msdn.microsoft.com/en-us/library/ms189461.aspx

    am trying to find the source that demonstrates the efficiency of using "unbounded preceding"...I have it somewhere <grin>

    will post back if I...

    J. Drew Allen
    Business Intelligence Analyst
    Philadelphia, PA

  • RE: LEFT JOIN

    Welsh Corgi (1/14/2016)


    I need to create a new table that has an Identity Column so that I can delete the duplicates.

    No, you don't. You can use a CTE to...

    J. Drew Allen
    Business Intelligence Analyst
    Philadelphia, PA

  • RE: LEFT JOIN

    Welsh Corgi (1/14/2016)


    Thanks.

    Does anyone have a script that could be adapted to correct the duplicate issue.

    Surely you've been around long enough to know how to set up a CTE with...

    J. Drew Allen
    Business Intelligence Analyst
    Philadelphia, PA

  • RE: LEFT JOIN

    Welsh Corgi (1/14/2016)


    Yes there are 3 duplicates when I do a INNER JOIN but I exclude them in the Insert and I keep getting PK Violations. :unsure:

    An INNER JOIN won't...

    J. Drew Allen
    Business Intelligence Analyst
    Philadelphia, PA

  • RE: LEFT JOIN

    Welsh Corgi (1/14/2016)


    I execute the following:

    SELECT ID

    FROM Postal

    WHERE ID = 'B5A 5E8'

    And it does not return any records.

    And what do you get when you execute the following code

    SELECT ZipCode

    FROM Postal_Codes_Import

    WHERE...

    J. Drew Allen
    Business Intelligence Analyst
    Philadelphia, PA

  • RE: LEFT JOIN

    Welsh Corgi (1/14/2016)


    That would help if I included the error. :blush:

    Violation of PRIMARY KEY constraint 'PK_Postal'. Cannot insert duplicate key in object 'dbo.Postal'. The duplicate key value is (B5A 5B4).

    I'm...

    J. Drew Allen
    Business Intelligence Analyst
    Philadelphia, PA

  • RE: combine a datetime coulmn and varchar into new Datetime

    sqlfriends (1/14/2016)


    Thank you, those are good tips.

    I checked the data, the distinct ones are not few. So I may have to do some replace to make the time correct.

    Thank you!

    You...

    J. Drew Allen
    Business Intelligence Analyst
    Philadelphia, PA

  • RE: Need help with SQL to get duplicate rows and still show unique fields in the rows and filter by NULL field when one or both are NULL

    ROW_NUMBER() is overused. Here the OP needs a single value from one record to be available across the entire partition, namely whether a NULL exists on any record in...

    J. Drew Allen
    Business Intelligence Analyst
    Philadelphia, PA

Viewing 15 posts - 2,821 through 2,835 (of 4,085 total)