Comparision of records for a given set of values in datatable

  • For example take example of following table.

    Student IDNameSectionPercentageSubject IdOther Activities

    1 ABCA 100123 NULL

    2 CDEA 50345 NULL

    2 CDEA 50 Good In sports

    3 EFGA 50 123 NULL

    3 EFGA 50345 NULL

    4 GHIA 100 Good In sports

    Now i have to write a stored procedure which takes input as student id, student name and section details as datatable and tells whether all the records passed in datatable have the same values for percentage, subject id, other activities or not .

    Any suggestions are helpful

  • select s.StudentID, s.Name, s.Section,

    DifferentRecords =

    CASE WHEN MAX(s.Percentage)<>MIN(s.Percentage)

    OR MAX(s.SubjectID)<>MIN(s.SubjectID)

    OR MAX(s.OtherActivities)<>MIN(s.OtherActivities)

    THEN 'yes'

    ELSE 'No'

    END

    from dbo.students s

    group by s.StudentID, s.Name, s.Section

    _____________________________________________________
    Microsoft Certified Master: SQL Server 2008
    XDetails Addin - for SQL Developers
    blog.sqlxdetails.com - Transaction log myths

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

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