Let's go by parts said Jack the Ripper:
I have to edit a giant Horrible report through Crystal Reports.
For reasons of compatibility of the software from which the report comes, I have had to insert a subreport within the report to access certain data.
Then:
I connect to my Base with a SQL Server 2 connection.
I am going to add command.
I copy the query that works great in Management Studio 2008 and I am ready to add the necessary parameters, leaving the query as follows:
.
SELECT TOP 1 isnull( dtssegcabv.dscv_fecharecepcion,0) as FechaRecepcion
FROM CabVenta
JOIN dtssegcabv ON CabVenta.cvescv_id = dtssegcabv.scv_id
WHERE CabVenta.cve_letra = {?cve_letra}
AND CabVenta.cve_codpvt={?cve_codpvt}
AND CabVenta.cve_nro={?cve_nro}
AND CabVenta.cvetco_cod={?cvetco_cod}
An Enter Values dialog opens (I understand these are test values, or default values? I don't quite get it). The issue is that:
-If I add a value to each parameter (a valid value in the DB):
So it interprets all those values as a column name. For example, if I assign A to the cve_letter parameter, it tells me 'Invalid Column name A'
-If I leave the parameters empty:
'Incorrect Syntax near the keyword and'
I insist that the query executed in SQL Managment Studio 2008 works.
Thanks for your help, I'll be attentive to comments.
Let's go by parts:
Whenever you program in SQL, all reserved names are capitalized, so it will be easier for you to determine what the values are.
They
SELECT
go on one line,FROM
they go on the next line, and so on to have greater clarity of what is being done.When there are multiple conditions, below the
WHERE
add indentation.The easier to read the query, the more happiness for those who develop it and who will maintain it.
Now with the code, check the following:
I hope that with this I can solve your question :D and if not, at least we collaborate so that there is better writing of queries :D