none
How to know if a DataType support DISTINCT ? RRS feed

  • Question

  • Hi,

    I have written an SQL generator, and, in some cases of complex join scenario, it would be nice to add a DISTINCT in my SELECT querys.

    However, I know some DataTypes don't support DISTINCT because they are not comparable.

    Is there a way to get dynamically the Comparable property of a specific DataType ? 

    thanks for any help.

    Thursday, April 8, 2010 11:36 AM

Answers

  • > Is there a way to get dynamically the Comparable property of a specific DataType ?

    You could test the type under System.Data.SqlTypes to see if it implements IComparable.  I'm not sure whether the .NET comparability corresponds well enough with DISTINCT in an SQL statement.

    Considering that working with the SqlTypes will pose the challenge of how to convert the types that your application knows about to the corresponding type under SqlTypes, if I were in your shoes I'd be seriously considering just hard-coding the logic to determine whether or not your type can be used with DISTINCT.

    Friday, April 9, 2010 12:58 AM

All replies

  • > Is there a way to get dynamically the Comparable property of a specific DataType ?

    You could test the type under System.Data.SqlTypes to see if it implements IComparable.  I'm not sure whether the .NET comparability corresponds well enough with DISTINCT in an SQL statement.

    Considering that working with the SqlTypes will pose the challenge of how to convert the types that your application knows about to the corresponding type under SqlTypes, if I were in your shoes I'd be seriously considering just hard-coding the logic to determine whether or not your type can be used with DISTINCT.

    Friday, April 9, 2010 12:58 AM
  • Hi,

    Thanks for your response.

    I will try the IComparable implementation, which would be more preferable to hard code this characterisitic.

    The correspondance between SqlTypes and Types is made with ADO.NET !

    Regards,

     

    Tuesday, April 13, 2010 11:51 AM
  • > The correspondance between SqlTypes and Types is made with ADO.NET !

    I am interested to know what ADO.NET method you are using to do this.  Thanks.

     

     

    Wednesday, April 14, 2010 1:26 AM
  • Hi Nicolas,

     

    I am writing to check the status of the issue on your side.  Would you mind letting us know how is the problem now? 

     

    If you need further assistance, please feel free to let me know.   I will be more than happy to be of assistance.

     

    Have a nice day!

     

     

    Best Regards,
    Lingzhi Sun

    MSDN Subscriber Support in Forum

    If you have any feedback on our support, please contact msdnmg@microsoft.com


    Please remember to mark the replies as answers if they help and unmark them if they provide no help.
    Welcome to the All-In-One Code Framework! If you have any feedback, please tell us.
    Tuesday, April 20, 2010 1:25 AM
    Moderator