I have a select command, and it returns answer records, but it also gives an error in Visual Studio 2010's query builder with this query:
SELECT *
FROM Orders
WHERE (BCode = 025) AND (Date BETWEEN '1390%' AND '1391%') OR
(Date BETWEEN '1390%' AND '1391%') AND (MCode = 0123456789)
The error is:
Error Message: the conversion of nvarchar value "0854697543"
overflowed an int column
Data types are
BCode : nvarchar(50)
Date : nvarchar(50)
MCode : nvarchar(10)
Where is the problem?
Shouldn't it be
AND (MCode = '0123456789')
?
Otherwise it will try to use 0123456789 as an integer which will lead to the conversion error.
In addition, you're repeating yourself in the logic (Date BETWEEN...
), more concise:
WHERE (Date BETWEEN '1390%' AND '1391%') AND
((BCode = 025) OR (MCode = '0123456789'))