fin difference between rowS ?

  • Hi all,

    I'm a beginner with t sql in sql server 2005

    i must to find the difference between four rows or several rows in a table and i don't know HOW to do this !!!!!

    i have this table call T_Experience

    tId => primary key

    descriptionPoste => int id come from another table

    domain => int id come from another table

    subDomain => int id come from another table

    priority => int , priority of the record (1,2,3,4 ...)

    my problem is follow :

    i must to compare record (12 - 13 => descriptionPoste 2412) with (14 - 15 => descriptionPoste 2413) and if there is a difference between domain, subDomain or priority i must to return a value !!

    i know the descriptionPoste for the each row

    tId | descriptionPoste | domain | subDomain | priority

    ------------------------------------------------------------

    12 | 2412 | 12 | -1 | 0

    13 | 2412 | 15 | 65 | 1

    14 | 2413 | 123 | 35 | 0

    15 | 2413 | 15 | 65 | 1

    the value return must be use for to lauch a command sql for to update table.

    my problem is to compare ? any idea ?

    Thanks for all

    Christophe

  • Pretty sure I haven't understood your requirements, but this should help you to create a solution.

    DECLARE @TABLE AS TABLE(

    tID INT,

    descriptionPoste INT,

    domain INT,

    subDomain INT,

    priority INT

    )

    INSERT INTO @TABLE

    SELECT 12, 2412, 12, -1, 0

    UNION ALL SELECT 13, 2412, 15, 65, 1

    UNION ALL SELECT 14, 2413, 123, 35, 0

    UNION ALL SELECT 15, 2413, 15, 65, 1

    SELECT CASE

    WHEN (SELECT COUNT(1)

    FROM (SELECT a.descriptionposte

    FROM @TABLE a,

    @TABLE b

    WHERE a.tid <> b.tid

    OR a.domain <> b.domain

    OR a.subdomain <> b.subdomain

    OR a.priority <> b.priority

    GROUP BY a.descriptionposte) a) <> 0 THEN 'Different'

    ELSE 'Same'

    END

    If you're still having trouble, then please read the article in my signature and post ddl, sample data and expected results.


    Forever trying to learn
    My blog - http://www.cadavre.co.uk/
    For better, quicker answers on T-SQL questions, click on the following...http://www.sqlservercentral.com/articles/Best+Practices/61537/
    For better, quicker answers on SQL Server performance related questions, click on the following...http://www.sqlservercentral.com/articles/SQLServerCentral/66909/

Viewing 2 posts - 1 through 2 (of 2 total)

You must be logged in to reply to this topic. Login to reply