Reputation: 190
I have come across a strange scenario while executing a query. I was surprised by the way Sql Server was executing the query.
Quote:
SELECT TOP 10
MR.MerchantContactFirstName +' '+ MR.MerchantContactLastName
AS MerchantName,
AISLTrans.DeviceID,AISLTrans.TransactionID,
AISLTrans.CardNumber,
AISLTrans.TransactionDateTime,
AISLTrans.TransactionStatus,
AISTRNSTYPE.TransactionType
AS TransactionRequestType,AISLTrans.TransactionAmount,
(AISLTrans.BasePointEarn+AISLTrans.BonusPointEarn)
AS 'Point Awarded'
FROM AISLoyaltyTransactions AISLTrans
INNER JOIN MerchantRegistration MR
ON AISLTrans.MerchantID = MR.MerchantID
INNER JOIN AISTransactionTypes AISTRNSTYPE
ON AISLTrans.ProcessingCode = AISTRNSTYPE.ProcessingCode
AND AISLTrans.TransactionType = AISTRNSTYPE.MessageType
WHERE **AISLTrans.TransactionType = 0200**
AND AISLTrans.ProcessingCode = 071000
ORDER BY AISLTrans.TransactionDateTime DESC
In above query the field ISLTrans,TransactionType works fine for all the values except 0200 it accepts all interger values though the field type is of varchar.
But when I give the value as 0200 it throws exception saying cannot convert varchar to int.
I am looking for why the query is still executing though I am providing integer value instead of varchar and if it is executing why its not accepting all the integer values which I provide.
Upvotes: 0
Views: 50
Reputation: 468
Implement a standard way while giving input.
If the AISLTrans.TransactionType filed type is integer, Use these code
AISLTrans.TransactionType = CAST(0200 AS INT)
else use these code
AISLTrans.TransactionType = '0200'
Upvotes: 1