Zen
Zen

Reputation: 7385

I just do not understand why this query does not pull results

Okay, this is the most simple query in the world, and it is somehow failing.

SELECT * FROM kal_auth.dbo.Login WHERE ID = 'Zen' AND PWD = CONVERT(varchar,'0x9248FEFE237DB009')

0x9248FEFE237DB009 is not hex, although it looks like it. but it converts to "Password"

I know this row exists, and its only the password field which is not returning results, this was learned by isolating them and testing.

The PWD field is varchar(16).

I do not understand this.

Upvotes: 3

Views: 111

Answers (2)

Martin Smith
Martin Smith

Reputation: 453057

Use

SELECT CONVERT(VARCHAR,0x9248FEFE237DB009) -- returns ’Hþþ#}° 

Not

SELECT CONVERT(varchar,'0x9248FEFE237DB009') -- returns 0x9248FEFE237DB009

By encasing it in quotes it gets treated as a string not as binary data meaning the conversion to varchar doesn't do anything!

Upvotes: 3

Maria Ioannidou
Maria Ioannidou

Reputation: 1564

I may be missing something here...

The result of CONVERT(varchar,'0x9248FEFE237DB009') is the same '0x9248FEFE237DB009' with 18 chars, isn't it? So how could it be equal to a 16 char password?

Upvotes: 3

Related Questions