I have a stock query in C # that generates a report with reportviewer. I have a CheckBox that when I click on it it does not show me the items with a zero balance and when I unmark it it shows the items with a zero balance.
>Since the query in SQL works perfectly, either passing parameter 1 to 0.
follow the code
private void btnPesquisar_Click(object sender, EventArgs e)
{
string pSaldo = cbEstoque.Checked == true ? "1" : "0";
this.SaldoEstoqueTableAdapter.Fill_EstProd(this.Estoque.SaldoEstoque, cbTipo.Text, cbArmazem.Text, pSaldo);
this.reportViewer1.RefreshReport();
}
Follow the query in sql
DECLARE @SALDO VARCHAR(10)
SET @SALDO = 0
SELECT
SB.B2_COD,
S1.B1_DESC,
S1.B1_TIPO,
SB.B2_LOCAL,
(SB.B2_QATU - SB.B2_RESERVA) AS SALDO
FROM SB2020 AS SB
INNER JOIN SB1020 AS S1 WITH (NOLOCK) ON S1.B1_COD = SB.B2_COD
WHERE SB.D_E_L_E_T_ <> '*' AND S1.D_E_L_E_T_ <> '*' AND S1.B1_TIPO = 'MP' AND SB.B2_LOCAL = '01'
AND ((SB.B2_QATU - SB.B2_RESERVA) >= 0 AND @SALDO = 0) OR ((SB.B2_QATU - SB.B2_RESERVA) > 0 AND @SALDO = 1)
AND S1.B1_TIPO = 'MP' AND SB.B2_LOCAL = '01'
ORDER BY S1.B1_DESC
Rovann got query error
SELECT
SB.B2_COD,
S1.B1_DESC,
S1.B1_TIPO,
SB.B2_LOCAL,
(SB.B2_QATU - SB.B2_RESERVA) AS SALDO
FROM SB2020 AS SB
INNER JOIN SB1020 AS S1 WITH (NOLOCK) ON S1.B1_COD = SB.B2_COD
WHERE SB.D_E_L_E_T_ <> '*' AND S1.D_E_L_E_T_ <> '*' AND S1.B1_TIPO = 'MP' AND SB.B2_LOCAL = '01'
AND (CASE
WHEN @SALDO = 1 THEN ((SB.B2_QATU - SB.B2_RESERVA) > 0)
ELSE ((SB.B2_QATU - SB.B2_RESERVA)>=0) END)
ORDER BY SB.B1_DESC
erro
Msg 102, Level 15, State 1, Line 13
Incorrect syntax near '>'.