错了语句为
Select @MaxId = Max(id) from @tableName where substring(convert(nvarchar,id),1,1)= convert(varchar,@tmpid)