Friday, March 23, 2012

Query

The look folwoing query:
select RequisicaoPassagem.rpdata as Data,
RequisicaoPassagem.rpcodigo as Cdigo,
RequisicaoPassagem.rpcpf as CPF,
RequisicaoPassagem.rpnomefavorecido,
(((RequisicaoPassagem.rpTarifa+RequisicaoPassagem.rpTaxaEmbarque)/10) +
(select distinct ((viagemdiariatipo.vdtValor*viagemdados.vdQte)/10 )
from viagemdiariatipo, viagemdados, RequisicaoPassagem
where viagemdiariatipo.vdtcodigo = viagemdadoS.vdtcodigo and
RequisicaoPassagem.rpcodigo=viagemdados.rpcodigo and
RequisicaoPassagem.stsCodigo=1 )) AS Total
from RequisicaoPassagem,
viagemdados,
viagemdiariatipo
where viagemdados.vdtCodigo = viagemdiariatipo.vdtCodigo and
RequisicaoPassagem.stsCodigo=1
order by rpdata desc
this return error:
Server: Msg 512, Level 16, State 1, Line 1
Subquery returned more than 1 value. This is not permitted when the subquery
follows =, !=, <, <= , >, >= or when the subquery is used as an expression.
What is this error?Mozart,
it looks like the correlated part of your subquery is returning more than
one row (the select distinct bit). You could restructure the query to prove
that is the case. If it is reasonable that the subquery returns > 1 row
you'll need to convert it to an aggregate to avoid the problem.
HTH,
Paul Ibison

No comments:

Post a Comment