Searching By UniqueIdentifier

  • So I have a table with several UniqueIdentifier columns. I am exploring the database to get a handle on my new position, and honestly have not used the UniqueIdentifier data type much before.

    Just out of curiosity I ran

    Select Count(*) As RecordCount

    ,EventID

    From dbo.Events

    Group By EventID

    The first record in the record set is:

    RecordCountEventID

    3631AB0164-6BC9-448D-BC3E-53FEA210365E

    Looking at the SAME TABLE I run the following

    Select *

    From dbo.Events

    Where EventID = '31AB0164-6BC9-448D-BC3E-53FEA210365E'

    --or--

    Select *

    From dbo.Events

    Where Cast(EventID As nVarchar(36)) = '31AB0164-6BC9-448D-BC3E-53FEA210365E'

    --or--

    Select *

    From dbo.Events

    Where Cast(EventID As nVarchar(Max)) = '31AB0164-6BC9-448D-BC3E-53FEA210365E'

    I tried a few other permutations of the Cast / Convert method, but in every case I do not return any records...yet the count says there should be 36 records returned.

    What am I missing?

    [font="Arial"]“Any fool can know. The point is to understand.”
    - Albert Einstein

    "DOH!"
    - Homer Simpson[/font]

  • Try:

    Select *

    From dbo.Events

    Where EventID = '{31AB0164-6BC9-448D-BC3E-53FEA210365E}'

    _____________________________________________
    "The only true wisdom is in knowing you know nothing"
    "O skol'ko nam otkrytiy chudnyh prevnosit microsofta duh!":-D
    (So many miracle inventions provided by MS to us...)

    How to post your question to get the best and quick help[/url]

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

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