Incorrect syntax near ','

Asked

Viewed 2,682 times

-2

The code is this:

<i> <%@LANGUAGE="VBSCRIPT" CODEPAGE="65001"%>

<!--#include virtual="aplicativos/arquivos.asp"-->
<!--#include virtual="aplicativos/JSON_UTIL_0.1.1.asp" -->
<!--#include virtual="aplicativos/JSON_2.0.4.asp" -->
<!--#include virtual="aplicativos/validacao.asp"-->

<%
'----------------------------------------'
Dim d

set d = ConverteRequestParaDicionario(Request)

acao                = d.item("acao")
chbeneficio         = d.item("chbeneficio")
'----------------------------------------'
select case acao
    case "salvarDesempregado"  SalvarDesempregado()
end select
'----------------------------------------'
sub SalvarDesempregado

if d.item("nome") = "" then
        nome = "null"
else
    nome = "'" & d.item("nome") & "'"
end if

if d.item ("rg") = "" then
    rg = "null"
else
    rg = "'" & d.item("rg") & "'"
end if

if d.item ("cpf") = "" then
    cpf = "null"
else
    cpf = "'" & d.item("cpf") & "'"
end if

if d.item ("CTPSserie") = "" then
    CTPSserie = "null"
else
    CTPSserie = "'" & d.item("CTPSserie") & "'"
end if

if d.item ("ctps") = "" then
    ctps = "null"
else
    ctps = "'" & d.item("ctps") & "'"

end if

if d.item ("status") = "" then
    status = "null"
else
    status = "'" & d.item("status") & "'"

end if
if d.item("cep") = "" then
    cep = "null"
else
    cep = "'" & d.item("cep") & "'"
end if

if d.item ("endereco") = "" then
    endereco = "null"
else
    endereco = "'" & d.item("endereco") & "'"
end if

if d.item ("numero") = "" then
    numero = "null"
else
    numero = "'" & d.item("numero") & "'"
end if

if d.item ("bairro") = "" then
    bairro = "null"
else
    bairro = "'" & d.item("bairro") & "'"

end if

if d.item ("municipio") = "" then
    municipio = "null"
else
    municipio = "'" & d.item("municipio") & "'"

end if
if d.item ("complemento") = "" then
    complemento = "null"
else
    complemento = "'" & d.item("complemento") & "'"

end if
if d.item("estado") = "" then
    estado = "null"
else
    estado"'" & d.item("estado") & "'"
end if

if d.item ("email") = "" then
    email = "null"
else
    email = "'" & d.item("email") & "'"
end if

if d.item ("telefone") = "" then
    telefone = "null"
else
    telefone = "'" & d.item("telefone") & "'"
end if

if d.item ("celular") = "" then
    celular = "null"
else
    celular = "'" & d.item("celular") & "'"

end if

if d.item ("empresa") = "" then
    empresa = "null"
else
    empresa = "'" & d.item("empresa") & "'"

end if
if d.item ("profissao") = "" then
    profissao = "null"
else
    profissao = "'" & d.item("profissao") & "'"

end if
if d.item("dispensa") = "" then
    dispensa = "null"
else
    dispensa = "'" & d.item("dispensa") & "'"
end if

if d.item ("emprecep") = "" then
    emprecep = "null"
else
    emprecep = "'" & d.item("emprecep") & "'"
end if

if d.item ("empreendereco") = "" then
    empreendereco = "null"
else
    empreendereco = "'" & d.item("empreendereco") & "'"
end if

if d.item ("emprenumero") = "" then
    emprenumero = "null"
else
    emprenumero = "'" & d.item("emprenumero") & "'"

end if

if d.item ("emprecomplemento") = "" then
    emprecomplemento = "null"
else
    emprecomplemento = "'" & d.item("emprecomplemento") & "'"

end if

if d.item ("emprebairro") = "" then
    emprebairro = "null"
else
    emprebairro = "'" & d.item("emprebairro") & "'"

end if

if d.item ("empremunicipio") = "" then
    empremunicipio = "null"
else
    empremunicipio = "'" & d.item("empremunicipio") & "'"

end if

if d.item ("selo") = "" then
    selo = "null"
else
    selo = "'" & d.item("selo") & "'"

end if

if d.item ("entrega") = "" then
    entrega = "null"
else
    entrega = "'" & d.item("entrega") & "'"

end if

if d.item ("validade") = "" then
    validade = "null"
else
    validade = "'" & d.item("validade") & "'"

end if

SQL = "exec dbo.sp_desemp_insereDesempregado " & chbeneficio & ",'" & nome & "','" & RG & "','" & CPF & "','" & cep & "','" & endereco & "','" & numero & "','" & bairro & "','" & municipio & "','" & complemento & "','" &estado & "','" & email & "','" & telefone & "','" & celular & "','" & CTPS & "','" & CTPSserie & "','" & empresa & "','" & profissao & "','" & dispensa & "','" & emprecep & "','" & empreendereco & "','" & emprenumero & "','" & emprecomplemento & "','" & emprebairro & "','" & empremunicipio & "','" & selo & "','"& entrega & "','" & validade & "'"

QueryToJSON(banco, SQL).flush
response.end
end sub
'----------------------------------------'
%> </i>

And the mistake I get is always this:

Microsoft OLE DB Provider for SQL Server error '80040e14'

Incorrect syntax near ','.

/aplicativos/JSON_UTIL_0.1.1.asp, line 5

I’ve looked everywhere, including here, and I can’t fix that mistake. Procedure works, I’ve tried it on SQL Server.

  • 2

    tries to replace this SQL line = "exec dbo.sp_desemp_insert & "','"

  • 2

    your question is very badly formatted, nor will I try to edit, not to lose some important detail. In the excerpt SQL = "exec dbo.sp_desemp_insereDesempregado " & chbeneficio & ",'" & nome & "','" & RG & "','" & the first concatenation by what seems to be missing a single quote.

  • It’s really hard to visualize all this. By the type of error probably some variable is with some reserved character (example quotes) and is breaking the code. I suggest that Voce speaks a Answer.write and Answer.end for each variable of the query, until identifying.

  • Melissa, I’m sorry if it’s badly formatted, I’m not good at explaining things, and I’m the first time I’ve asked you something. in chbeneficio, no single quotes pq is an int value and the others are strings.

  • aa_asp I tried Sponse.write and I couldn’t get to the root of the T.T problem

1 answer

1


I don’t understand ASP/VBSCRIPT but the languages have a lot in common, which allowed us to understand what the code does; and how it does it.

In the code transcribed for this topic I noticed that the contents of the variables were delimited by summits ('). For example, if in d.item("nome") we have the content Natália, then in the stretch

if d.item("nome") = "" then
        nome = "null"
else
    nome = "'" & d.item("nome") & "'"
end if

at the end we will have 'Natália' in nome, with summits in the variable content.

When using the following SQL command snippet

SQL = "exec dbo.sp_desemp_insereDesempregado " & "'" & nome & "','" ...

what will we have in SQL is

exec dbo.sp_desemp_insereDesempregado ''Natália'',' ...

I mean, there are summits...

I suggest that in command you mount SQL remove all summits; it would look like this:

SQL = "exec dbo.sp_desemp_insereDesempregado " & nome & "," ...

If space is required before and after the concatenation operator &, watch out for the stretch &estado.

  • even with the changes, the same error persists

  • @Nath.S2 (1) Display on screen (response.write?) the content of SQL, instead of sending to run by SQL Server. This makes it easy to analyze what was mounted on SQL and find probable causes. (2) If possible add to the end of the text of your question as was the new command mount SQL; (3) If you still don’t find the cause, you could add at the end of the text of your question the content of SQL?

Browser other questions tagged

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