How to use SQL LIKE

Asked

Viewed 64 times

0

I’m trying to assemble a string that makes a filter to compare only a piece of a numbering. I tried to make an appeal and looked for several ways to do it and so far I could not.

using (NFSeDataContext context = new NFSeDataContext(ConnNFSe))
            {
                context.Connection.Open();

                var _s = (from p in context.NFS_Parcelas
                          join q in context.NFBP_CONCILIACAO_BRASPAGs on p.NFPA_CD_UNIDADE equals q.NFBP_CD_UNIDADE
                          where 
                            _idUnidade == p.NFPA_CD_UNIDADE
                           & _dtCred == p.NFPA_DT_MOVIMENTO
                           & p.NFPA_TX_COMPLEMENTO.Contains(q.NFBP_TID)

                          select new
                          {
                              p.NFPA_CD_UNIDADE,
                              q.NFBP_DT_FLUXO_CAIXA,
                              q.NFBP_COD_AUTORIZACAO,
                              q.NFBP_TID,
                              q.NFBP_VL_BRUTO_TRANSACAO,
                              q.NFBP_VL_LIQUIDO_TRANSACAO,
                              p.NFPA_NR_PARCELA,
                              q.NFBP_BANDEIRA
                          }).Distinct().ToList();


                context.Connection.Close();
                grvConciliacaoBraspag.DataSource = _s;
                grvConciliacaoBraspag.DataBind();


            } 

In this code q.NFBP_TID presents as for example a chunk representing the value:

104349099700D67C2012

p.NFPA_TX_COMPLEMENTO displays a snippet that displays the value:

VISA13010000104349099700D67C2012BP 1201

If you compare the two results:

->104349099700D67C2012<-

VISA13010000 ->104349099700D67C2012<- BP 1201

I’m pretty sure that this Contains check I did was wrong. That was one of the trial examples. I just posted the code to get a sense of my doubt.

  • 6

    http://answall.com/q/91933/101 Duplicate?

  • I believe so @bigown

  • @jbueno Sorry I didn’t inform you this, which is of great importance... It is within a Linq. Both in the start, end and contains it gives a not supported Exception.

  • @bigown, I visualized this situation and my problem and even doubt is whether it works in Latin. Excuse me even for not speaking, because in the 3 situations (start, end or contains) it gives a not supported Exception.

1 answer

2


try to use the SqlMethods.Like instead of contains.

SqlMethods.Like(p.NFPA_TX_COMPLEMENTO, "%" + q.NFBP_TID + "%")

Browser other questions tagged

You are not signed in. Login or sign up in order to post.