Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Database & SysAdmin
  3. Database
  4. Select Distinct by an Image Field

Select Distinct by an Image Field

Scheduled Pinned Locked Moved Database
csharpquestionasp-netsharepoint
8 Posts 4 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • V Offline
    V Offline
    Vimalsoft Pty Ltd
    wrote on last edited by
    #1

    i have an interesting question for you guys.

    SELECT S.SCHOOLID AS [SCHOOLID],S.SCHOOLNAME AS [SCHOOLNAME],SP.PHOTO AS [PHOTO]
    FROM SCHOOLPHOTO SP
    INNER JOIN SCHOOL S
    ON SP.SCHOOLID = SP.SCHOOLID
    WHERE S.SCHOOLID IN (SELECT SCHOOLID FROM #SCHOOLS)

    the Photo Field is an Image Datatype Field, i now you can use them in a Distinct or group by , How can i go by have that field there without casting it , because if i cast it it will not work together in Silverlight or any other image control. Thanks

    Vuyiswa Maseko, Spoted in Daniweb-- Sorry to rant. I hate websites. They are just wierd. They don't behave like normal code. C#/VB.NET/ASP.NET/SQL7/2000/2005/2008 http://www.vuyiswamaseko.com vuyiswa@its.co.za http://www.itsabacus.co.za/itsabacus/

    D 1 Reply Last reply
    0
    • V Vimalsoft Pty Ltd

      i have an interesting question for you guys.

      SELECT S.SCHOOLID AS [SCHOOLID],S.SCHOOLNAME AS [SCHOOLNAME],SP.PHOTO AS [PHOTO]
      FROM SCHOOLPHOTO SP
      INNER JOIN SCHOOL S
      ON SP.SCHOOLID = SP.SCHOOLID
      WHERE S.SCHOOLID IN (SELECT SCHOOLID FROM #SCHOOLS)

      the Photo Field is an Image Datatype Field, i now you can use them in a Distinct or group by , How can i go by have that field there without casting it , because if i cast it it will not work together in Silverlight or any other image control. Thanks

      Vuyiswa Maseko, Spoted in Daniweb-- Sorry to rant. I hate websites. They are just wierd. They don't behave like normal code. C#/VB.NET/ASP.NET/SQL7/2000/2005/2008 http://www.vuyiswamaseko.com vuyiswa@its.co.za http://www.itsabacus.co.za/itsabacus/

      D Offline
      D Offline
      David Mujica
      wrote on last edited by
      #2

      How about generating a hash code for your image and store that value in your table along with the image. You could then use the hash code in your group by clause. check this article out ... http://www.vcskicks.com/image-hash.php[^] It was the first thing that popped up in my Google search. Good luck. :thumbsup:

      V 1 Reply Last reply
      0
      • D David Mujica

        How about generating a hash code for your image and store that value in your table along with the image. You could then use the hash code in your group by clause. check this article out ... http://www.vcskicks.com/image-hash.php[^] It was the first thing that popped up in my Google search. Good luck. :thumbsup:

        V Offline
        V Offline
        Vimalsoft Pty Ltd
        wrote on last edited by
        #3

        I need a Solution in T-SQL

        Vuyiswa Maseko, Spoted in Daniweb-- Sorry to rant. I hate websites. They are just wierd. They don't behave like normal code. C#/VB.NET/ASP.NET/SQL7/2000/2005/2008 http://www.vuyiswamaseko.com vuyiswa@its.co.za http://www.itsabacus.co.za/itsabacus/

        P L 2 Replies Last reply
        0
        • V Vimalsoft Pty Ltd

          I need a Solution in T-SQL

          Vuyiswa Maseko, Spoted in Daniweb-- Sorry to rant. I hate websites. They are just wierd. They don't behave like normal code. C#/VB.NET/ASP.NET/SQL7/2000/2005/2008 http://www.vuyiswamaseko.com vuyiswa@its.co.za http://www.itsabacus.co.za/itsabacus/

          P Offline
          P Offline
          Pete OHanlon
          wrote on last edited by
          #4

          What version of SQL Server are you using? If it's sufficiently advanced, you could apply this as a CLR Trigger.

          Forgive your enemies - it messes with their heads

          My blog | My articles | MoXAML PowerToys | Mole 2010 - debugging made easier - my favourite utility

          V 1 Reply Last reply
          0
          • P Pete OHanlon

            What version of SQL Server are you using? If it's sufficiently advanced, you could apply this as a CLR Trigger.

            Forgive your enemies - it messes with their heads

            My blog | My articles | MoXAML PowerToys | Mole 2010 - debugging made easier - my favourite utility

            V Offline
            V Offline
            Vimalsoft Pty Ltd
            wrote on last edited by
            #5

            I am SQL 2008

            Vuyiswa Maseko, Spoted in Daniweb-- Sorry to rant. I hate websites. They are just wierd. They don't behave like normal code. C#/VB.NET/ASP.NET/SQL7/2000/2005/2008 http://www.vuyiswamaseko.com vuyiswa@its.co.za http://www.itsabacus.co.za/itsabacus/

            P 1 Reply Last reply
            0
            • V Vimalsoft Pty Ltd

              I am SQL 2008

              Vuyiswa Maseko, Spoted in Daniweb-- Sorry to rant. I hate websites. They are just wierd. They don't behave like normal code. C#/VB.NET/ASP.NET/SQL7/2000/2005/2008 http://www.vuyiswamaseko.com vuyiswa@its.co.za http://www.itsabacus.co.za/itsabacus/

              P Offline
              P Offline
              Pete OHanlon
              wrote on last edited by
              #6

              Then it's job done. You can use a SQL CLR trigger and store the hash when the image is inserted or updated.

              Forgive your enemies - it messes with their heads

              My blog | My articles | MoXAML PowerToys | Mole 2010 - debugging made easier - my favourite utility

              V 1 Reply Last reply
              0
              • P Pete OHanlon

                Then it's job done. You can use a SQL CLR trigger and store the hash when the image is inserted or updated.

                Forgive your enemies - it messes with their heads

                My blog | My articles | MoXAML PowerToys | Mole 2010 - debugging made easier - my favourite utility

                V Offline
                V Offline
                Vimalsoft Pty Ltd
                wrote on last edited by
                #7

                this did the Job

                ;with cteSchools as (SELECT DISTINCT S.SCHOOLID AS [SCHOOLID],S.SCHOOLNAME AS [SCHOOLNAME]
                FROM SCHOOL S

                WHERE S.SCHOOLID IN (SELECT SCHOOLID FROM #SCHOOLS))

                SELECT S.SCHOOLID AS [SCHOOLID],S.SCHOOLNAME AS [SCHOOLNAME],SP.PHOTO AS [PHOTO]
                FROM cteSCHOOLS S
                CROSS APPLY (Select TOP (1) PHOTO from SchoolPhoto SP
                WHERE SP.SCHOOLID = S.SCHOOLID
                ORDER BY SCHOOLID DESC) SP

                Thanks

                Vuyiswa Maseko, Spoted in Daniweb-- Sorry to rant. I hate websites. They are just wierd. They don't behave like normal code. C#/VB.NET/ASP.NET/SQL7/2000/2005/2008 http://www.vuyiswamaseko.com vuyiswa@its.co.za http://www.itsabacus.co.za/itsabacus/

                1 Reply Last reply
                0
                • V Vimalsoft Pty Ltd

                  I need a Solution in T-SQL

                  Vuyiswa Maseko, Spoted in Daniweb-- Sorry to rant. I hate websites. They are just wierd. They don't behave like normal code. C#/VB.NET/ASP.NET/SQL7/2000/2005/2008 http://www.vuyiswamaseko.com vuyiswa@its.co.za http://www.itsabacus.co.za/itsabacus/

                  L Offline
                  L Offline
                  Lost User
                  wrote on last edited by
                  #8

                  Use the T-SQL function hashbytes like this:

                  select hashbytes('MD5', 'your value')

                  1 Reply Last reply
                  0
                  Reply
                  • Reply as topic
                  Log in to reply
                  • Oldest to Newest
                  • Newest to Oldest
                  • Most Votes


                  • Login

                  • Don't have an account? Register

                  • Login or register to search.
                  • First post
                    Last post
                  0
                  • Categories
                  • Recent
                  • Tags
                  • Popular
                  • World
                  • Users
                  • Groups