• dwilliscp (5/8/2013)


    Since the first table had one record with a delivery of 00835308 and the second had none, I would have expected the SQL to return one record. What I got was two records that are the same.

    The code I have placed here.. shows the problem, but the WHERE was added to show why my query is failling with a PK failure.... and the Insert Into was removed.

    Either the first or second table has two rows with that value based on the query you posted.

    I would suggest that you change the datatype at least in your temp table to an int.

    select *

    FROM #Delivery Left Outer JOIN

    details_2 ON cast(#Delivery.Delivery as int) = cast(details_2.Delivery_Doc as int) AND

    cast(#Delivery.Delivery_Item as int) = cast(details_2.Delivery_Item as int)

    Where cast(delivery as int) = 83535308

    Based on that query every row has to have a value that is directly castable to an int. Save yourself the hassles and just change the datatype.

    _______________________________________________________________

    Need help? Help us help you.

    Read the article at http://www.sqlservercentral.com/articles/Best+Practices/61537/ for best practices on asking questions.

    Need to split a string? Try Jeff Modens splitter http://www.sqlservercentral.com/articles/Tally+Table/72993/.

    Cross Tabs and Pivots, Part 1 – Converting Rows to Columns - http://www.sqlservercentral.com/articles/T-SQL/63681/
    Cross Tabs and Pivots, Part 2 - Dynamic Cross Tabs - http://www.sqlservercentral.com/articles/Crosstab/65048/
    Understanding and Using APPLY (Part 1) - http://www.sqlservercentral.com/articles/APPLY/69953/
    Understanding and Using APPLY (Part 2) - http://www.sqlservercentral.com/articles/APPLY/69954/