Fórum Problema QUERY não tráz o select #279795
02/05/2005
0
Boa tarde, pessoal!!!
Estou com o seguinte problema. Tenho que selecionar o valor máximo de um campo em minha tabela. Quando eu rodo no SQL Server (Vejam exemplo abaixo), roda blz:
select max(CONTE1) as CONTE1 from CONTLUGARCINEMA
where DATA = ´2005.06.01´
and COD_HOR = ´176´
and CODIASEM = ´7´
Mas quando eu ro no Delpli, não tráz o valor pra mim. Vejam abaixo:
with dm2.qryContLugarCinema do
begin
Close;
SQL.Clear;
SQL.Add(´select max(CONTE1) as CONTE1 from CONTLUGARCINEMA´);
SQL.Add(´where DATA like ´ + QuotedStr(medtData.Text) + ´´);
SQL.Add(´and CODIASEM = :P_CODIASEM´);
SQL.Add(´and COD_HOR = :P_COD_HOR´);
dm2.qryContLugarCinema.Parameters.ParamByName
´P_CODIASEM´).Value :=
StrToInt(dbedtCodDiaSemana.Text);
dm2.qryContLugarCinema.Parameters.ParamByName(´P_COD_HOR´).Value :=
StrToInt(dbedtCodHorario.Text);
Open;
end;
Se alguém puder me ajudar, agradeço.
Estou usando SQL Server...
Abraços!!!
Estou com o seguinte problema. Tenho que selecionar o valor máximo de um campo em minha tabela. Quando eu rodo no SQL Server (Vejam exemplo abaixo), roda blz:
select max(CONTE1) as CONTE1 from CONTLUGARCINEMA
where DATA = ´2005.06.01´
and COD_HOR = ´176´
and CODIASEM = ´7´
Mas quando eu ro no Delpli, não tráz o valor pra mim. Vejam abaixo:
with dm2.qryContLugarCinema do
begin
Close;
SQL.Clear;
SQL.Add(´select max(CONTE1) as CONTE1 from CONTLUGARCINEMA´);
SQL.Add(´where DATA like ´ + QuotedStr(medtData.Text) + ´´);
SQL.Add(´and CODIASEM = :P_CODIASEM´);
SQL.Add(´and COD_HOR = :P_COD_HOR´);
dm2.qryContLugarCinema.Parameters.ParamByName
´P_CODIASEM´).Value :=
StrToInt(dbedtCodDiaSemana.Text);
dm2.qryContLugarCinema.Parameters.ParamByName(´P_COD_HOR´).Value :=
StrToInt(dbedtCodHorario.Text);
Open;
end;
Se alguém puder me ajudar, agradeço.
Estou usando SQL Server...
Abraços!!!
Cristianojedi
Curtir tópico
+ 0
Responder
Posts
02/05/2005
Wly
Mas quando eu ro no Delpli, não tráz o valor pra mim. Vejam abaixo:
with dm2.qryContLugarCinema do
begin
Close;
SQL.Clear;
SQL.Add(´select max(CONTE1) as CONTE1 from CONTLUGARCINEMA´);
SQL.Add(´where DATA like ´ + QuotedStr(medtData.Text) + ´´);
SQL.Add(´and CODIASEM = :P_CODIASEM´);
SQL.Add(´and COD_HOR = :P_COD_HOR´);
dm2.qryContLugarCinema.Parameters.ParamByName
´P_CODIASEM´).Value :=
StrToInt(dbedtCodDiaSemana.Text);
dm2.qryContLugarCinema.Parameters.ParamByName(´P_COD_HOR´).Value :=
StrToInt(dbedtCodHorario.Text);
Open;
end;
Tente fazer deste modo, utilizando uma constante, assim :
Const SQL_Cinema : String = ´Select Max(CONTE1) as CONTE1 ´+ ´From CONTLUGARCINEMA ´+ ´Where DATA=:prnData ´+ ´and CODIASEM=:prnCODIASEM ´+ ´and COD_HOR=:prnCOD_HOR ´; begin with dm2.qryContLugarCinema do begin Close; SQL.Clear; SQL.Add(SQL_Cinema); ParamByName(´prnData).AsDateTime := StrToDateTime(medtData.Text); ParamByName(´prnCODIASEM).value := StrToInt(dbedtCodDiaSemana.Text); ParamByName(´prnCOD_HOR).value := StrToInt(dbedtCodHorario.Text); Open; end; end;
Responder
Gostei + 0
02/05/2005
Rafael Santana
boa tarde, amigo
coloque o seu LIKE com parâmetro também...aí ao invés disso...
SQL.Add(´where DATA like ´ + QuotedStr(medtData.Text) + ´´);
ficaria assim
SQL.Add(´where data like :DATA)
SQL.PARAMBYNAME(´DATA´).VALUE:=QuotedStr(medtData.Text)+´¬´
T+, AMIGO
coloque o seu LIKE com parâmetro também...aí ao invés disso...
SQL.Add(´where DATA like ´ + QuotedStr(medtData.Text) + ´´);
ficaria assim
SQL.Add(´where data like :DATA)
SQL.PARAMBYNAME(´DATA´).VALUE:=QuotedStr(medtData.Text)+´¬´
T+, AMIGO
Responder
Gostei + 0
Clique aqui para fazer login e interagir na Comunidade :)