Sql-server – Converting Access SQL HAVING command to T-SQL

ms accesssql server

I have this SELECT query I need to convert to a T-SQL view:

SELECT 
    T_Compras.Guia, T_Compras.Data, T_Compras.Id_Embarcação, 
    T_Compras.[Nº Maré], T_ComprasDet.Id_Peixe, 
    T_ComprasDet.Id_Tamanho, 
    SUM([Peso Kg] * [Caixas]) AS Peso, 
    T_ComprasDet.Id_Frescura, Q_Guia_Fact.Valor
FROM 
    (T_Compras 
LEFT JOIN 
    Q_Guia_Fact ON T_Compras.Guia = Q_Guia_Fact.Guia) 
INNER JOIN 
    T_ComprasDet ON T_Compras.Guia = T_ComprasDet.Guia
GROUP BY 
    T_Compras.Guia, T_Compras.Data, T_Compras.Id_Embarcação, 
    T_Compras.[Nº Maré], T_ComprasDet.Id_Peixe, 
    T_ComprasDet.Id_Tamanho, T_ComprasDet.Id_Frescura, 
    Q_Guia_Fact.Valor
HAVING 
    (((T_Compras.Guia) = [Forms]![F_Compras]![Guia]));

I am able to get everything working but I don't know how that last HAVING clause would be in T-SQL. In Access what it is doing is prompting the user for a guide number (guide="guia") so that it only shows rows with that guide number.

Thanks in advance!

Best Answer

Create the view without the HAVING clause, and when you query the view, filter it using:

WHERE Guia = ????

...with your "????" being the value that you're passing in from your form.