你会认为两者都会带来相同的结果。但这并不是因为转换正在修剪 2 个零,因此第 2 个不会返回结果,因为它将 446641 与 446641 进行比较
select memberID,
Photo as PhotoBlob
from SomeTable
WHERE memberId = '00446641'
Select memberID,
Photo as PhotoBlob
from SomeTable
WHERE memberId = convert(char(13), 00446641) - this is trimming off the 2 zeros
无论出于什么奇怪的原因,memberID 都不是 int,而是该表中的 char(13)
更新
这是上下文:
public static MemberPhoto RetrieveMemberPhotoFromBlob(Int64 contractNumber)
{
Database db = DatabaseFactory.CreateDatabase(Config.DbConnectionString_MemberPhotos);
using ( DbCommand cmd = db.GetSqlStringCommand(string.Format(@" Select memberID,
Photo as PhotoBlob
from SomeTable
WHERE memberId = convert(char(13), @{0})","memberID")))
{
try
{
db.AddInParameter(cmd, "@contractNumber", DbType.Int64, contractNumber);