sql server - Sub query returning all values and then applying where condition -


i having issue query in 1 particular environment/database if data similar. here simplified scenario:

table - 1 column - id (long)

id 1 2 3 

table b - 2 columns - value(varchar) , field2(varchar)

  value field2 1)abc   notkey 2)test  notkey 3)1     key 4)1.56  notkey 

when run query

select * table id in(select value table b field2 = 'key') 

i error

result: conversion failed when converting varchar value 'abc' (earlier had value erraneously 'notkey') data type int.

on 1 database. in 3 other databases, value returns correctly "1".

i using sql server 2008. might issue here?

you gave wrong filter filter leads error.

the errror happens when select:

select * tablea id in(select value tableb field2 = 'notkey') 

you have cast 1 of columns

select * tablea cast( id nvarchar(20)) in(select value tableb field2 = 'notkey') 

http://sqlfiddle.com/#!6/e9223/23


Comments

Popular posts from this blog

node.js - Mongoose: Cast to ObjectId failed for value on newly created object after setting the value -

[C++][SFML 2.2] Strange Performance Issues - Moving Mouse Lowers CPU Usage -

ios - Possible to get UIButton sizeThatFits to work? -