Home I haven't used single quotes on a VARCHAR column but query still executes?
Reply: 0

I haven't used single quotes on a VARCHAR column but query still executes?

user774
1#
user774 Published in June 19, 2018, 6:20 pm

The below query filters on two columns in the WHERE clause. Both columns are of VARCHAR datatype. Purely by mistake I ran the query without putting single quotes around the column2 values and it ran successfully and return the correct result set.

Query:

SELECT * 
FROM table
WHERE column1 = 'QTR12345678'
  AND column2 IN (120012, 220015)

Note: if I only search on column2 then I get the expected error

Conversion failed when converting the varchar value...

It seems like the SQL engine implicitly converts the value from numeric to varchar is this instance. Why?

(I'm using SQL Server 2012 SP2)

You need to login account before you can post.

About| Privacy statement| Terms of Service| Advertising| Contact us| Help| Sitemap|
Processed in 0.352606 second(s) , Gzip On .

© 2016 Powered by mzan.com design MATCHINFO