fallo en la insercion

fallo en la insercion

Postby artu01 » Tue Mar 12, 2019 10:58 pm

Gente:
a pesar que creo campos con valor por default al momento de insertar me bota error si hago asi

Code: Select all  Expand view

cSQL := " insert into #ppru "
cSQL += "values('123456','T25CD',,,20.4444,120.00,,,'01','T25CD')"
 


pero si le paso valores a todos los campos inclusive a los campos con valor por defecto, no tengo falla de insercion
Code: Select all  Expand view

    cSQL := " insert into #ppru "
    cSQL += "values('123456','T25CD',0,0,20.4444,120.00,0,0,'01','T25CD')"
 


Asi trabaja ADO o es que estoy haciendo algo mal?
Code: Select all  Expand view

    cSQL := "CREATE TABLE #ppru"
    cSQL += "("
    cSQL += "numero CHAR(6) NOT NULL, "
    cSQL += "articu VARCHAR(10) NOT NULL, "
    cSQL += "cantid int DEFAULT 0, "
    cSQL += "mts INT DEFAULT 0,"
    cSQL += "precio NUMERIC(12,4),"
    cSQL += "total NUMERIC(10,2),"
    cSQL += "unid int DEFAULT 0,"
    cSQL += "stock int DEFAULT 0,"
    cSQL += "codusu char(6) NOT NULL,"
    cSQL += "subart varchar(10) "
    cSQL += ")"

    Try
        oCon:Execute( cSQL )
    Catch
        MsgInfo( "Table Create ppru Failed" )
    End try

    cSQL := " insert into #ppru "
    //cSQL += "values('123456','T25CD',,,20.4444,120.00,,,'01','T25CD')"      ===> consigo error en la insercion
    cSQL += "values('123456','T25CD',0,0,20.4444,120.00,0,0,'01','T25CD')"   ===> sin error

    Try
        oCon:Execute( cSQL )
    Catch
        MsgInfo( "Fallo en la insercion" )
    End try
 
fwh 17.12, harbour 3.2.0, pelles C, bcc7, Ms-Sql
artu01
 
Posts: 397
Joined: Fri May 11, 2007 8:20 pm
Location: Lima

Re: fallo en la insercion

Postby cmsoft » Wed Mar 13, 2019 11:38 am

Indicale que campos queres llenar con los valores.
Code: Select all  Expand view

cSQL := " insert into #ppru (numero,articu,precio,total,codusu,subart) "
cSQL += "values('123456','T25CD',20.4444,120.00,'01','T25CD')"
 
User avatar
cmsoft
 
Posts: 1204
Joined: Wed Nov 16, 2005 9:14 pm
Location: Mercedes - Bs As. Argentina

Re: fallo en la insercion

Postby artu01 » Wed Mar 13, 2019 2:25 pm

Gracias Cesar no recordaba que podía hacerlo de esa forma
fwh 17.12, harbour 3.2.0, pelles C, bcc7, Ms-Sql
artu01
 
Posts: 397
Joined: Fri May 11, 2007 8:20 pm
Location: Lima

Re: fallo en la insercion

Postby nageswaragunupudi » Thu Mar 14, 2019 12:41 am

You can also write
Code: Select all  Expand view
  cSQL += "values('123456','T25CD',DEFAULT,DEFAULT,20.4444,120.00,DEFAULT,DEFAULT,'01','T25CD')"
 
Regards

G. N. Rao.
Hyderabad, India
User avatar
nageswaragunupudi
 
Posts: 10316
Joined: Sun Nov 19, 2006 5:22 am
Location: India

Re: fallo en la insercion

Postby artu01 » Thu Mar 14, 2019 1:33 pm

Thank Mr. Rao !
i'll try that alternative
fwh 17.12, harbour 3.2.0, pelles C, bcc7, Ms-Sql
artu01
 
Posts: 397
Joined: Fri May 11, 2007 8:20 pm
Location: Lima

Re: fallo en la insercion

Postby Armando » Fri Mar 15, 2019 4:42 am

artu01:

La opciones que te han sugerido por supuesto funcionan aunque tienen un pequeño
inconveniente, puedes perder la relación entre el nombre de un campo y su
correspondiente valor, una opción que puede ayudar es esta:

Code: Select all  Expand view

            cCmdSql := "INSERT INTO " +;
                                "AppSap.DetNdc " +;
                            "SET " +;
                                "DET_SER = '" + oRsFil:Fields("DET_SER"):Value + "'," +;
                                "DET_NDC = " + STR(oRsFil:Fields("DET_NDC"):Value,07,0) + "," +;
                                "DET_CTD = " + STR(oRsFil:Fields("DET_CTD"):Value,09,3) + "," +;
                                "DET_UDM = '" + oRsFil:Fields("DET_UDM"):Value + "'," +;
                                "DET_POR = " + STR(IIF(oRsFil:Fields("DET_POR"):Value,1,0),1,0) + "," +;
                                "DET_DES = '" + cDes + "'," +;
                                "DET_PUN = " + STR(oRsFil:Fields("DET_PUN"):Value,11,2) + "," +;
                                "DET_IMP = " + STR(oRsFil:Fields("DET_IMP"):Value,11,2)
            TRY
                oApp:oCon:Execute(cCmdSql)
            CATCH oError
                MsgInfo("No pude ejecutar el comando " + cCmdSql,oApp:cAplicacion)
                oApp:oCon:ShowError()
            END
 


Saludos
SOI, s.a. de c.v.
estbucarm@gmail.com
http://www.soisa.mex.tl/
http://sqlcmd.blogspot.com/
Tel. (722) 174 44 45
Carpe diem quam minimum credula postero
User avatar
Armando
 
Posts: 3085
Joined: Fri Oct 07, 2005 8:20 pm
Location: Toluca, México

Re: fallo en la insercion

Postby artu01 » Sat Mar 16, 2019 12:13 am

Muchas gracias armando por tu ayuda!
fwh 17.12, harbour 3.2.0, pelles C, bcc7, Ms-Sql
artu01
 
Posts: 397
Joined: Fri May 11, 2007 8:20 pm
Location: Lima


Return to FiveWin para Harbour/xHarbour

Who is online

Users browsing this forum: No registered users and 32 guests