Note that there are some explanatory texts on larger screens.

plurals
  1. POSQL query not returning record
    primarykey
    data
    text
    <p>I am trying to retrieve a record from a table with a given field value. The query is:</p> <pre><code>declare @imei varchar(50) set @imei = 'ee262b57-ccb4-4a2b-8410-6d8621fd9328' select * from tblDevices where imei = @imei </code></pre> <p>which returns nothing.</p> <p>If I comment out the where clause all records are returned, including the one I am looking for. The value is clearly in the table field and matches exactly, but I cannot get the where clause to work.</p> <p>I literally copied the value out of the table to ensure it was correct. </p> <p>I would appreciate any guidance on my mistake.</p> <p><strong>Table def:</strong></p> <pre><code>CREATE TABLE [dbo].[tblDevices]( [id] [int] IDENTITY(1,1) NOT NULL, [create_date] [datetime] NOT NULL, [update_date] [datetime] NOT NULL, [other_id] [int] NULL, [description] [varchar](50) COLLATE SQL_Latin1_General_CP1_CI_AS NOT NULL, [authorized] [int] NOT NULL, [imei] [varchar](50) COLLATE SQL_Latin1_General_CP1_CI_AS NOT NULL, CONSTRAINT [PK_tblDevices] PRIMARY KEY CLUSTERED ( [id] ASC )WITH (IGNORE_DUP_KEY = OFF) ON [PRIMARY] ) ON [PRIMARY] </code></pre> <p><strong>Edit</strong></p> <p>Using user2864740 suggestion, I queried the following:</p> <pre><code>select hashbytes('SHA1', imei) as h1 from tblDevices where id =8 returns: 0x43F9067C174B2F2F2C0FFD17B9AC7F54B3C630A2 select hashbytes('SHA1', @imei) as h2 returns: 0xB9B82BB440B04729B2829B335E6D6B450572D2AB </code></pre> <p>So, I am not sure what this means. My poor little brain is having a hard time understanding that A &lt;> A?! What is going on here if it's not a collation issue? How can two identical values not be considered equal?</p> <p><strong>Edit 2</strong></p> <p>this is the table record I want:</p> <pre><code>8 2013-10-22 12:43:10.223 2013-10-22 12:43:10.223 -1 1 ee262b57-ccb4-4a2b-8410-6d8621fd9328 </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload