Forum Replies Created

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

  • RE: Select Latest record by comparing 2 tables.

    This should give you what you need:

    WITH Combined AS(

    SELECT MachineID, InstanceKey, TimeKey, RevisionID, rowversion, Account, SchemaClass

    FROM TABLE_A

    UNION ALL

    SELECT MachineID, InstanceKey, TimeKey, RevisionID, rowversion, Account, SchemaClass

    FROM TABLE_B

    )

    , Ordered AS (

    SELECT MachineID,...

  • 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>,...

  • 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...

  • 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...

  • 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...

  • 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

  • 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

  • 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 -...

  • 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...

  • 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...

  • 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...

  • 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...

  • 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...

  • 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...

  • 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...

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