Ver Mensaje Individual
  #2 (permalink)  
Antiguo 23/11/2007, 09:23
Avatar de Kelpie
Kelpie
 
Fecha de Ingreso: febrero-2002
Ubicación: NorthSpain
Mensajes: 609
Antigüedad: 22 años, 3 meses
Puntos: 8
Re: Problemas Al Declarar Un Query De Mssql En Php

Podrías probar esto:

$FI = '01/10/2007 00:00';
$FF = '22/11/2007 23:59';

$vendedor = '15';
$producto = '1';


$sqt="SELECT C.cod_cte, C.razon_social,";
$sqt.="isnull((select top 1 fecha";
$sqt.=" from entysal where status <> 'C' and fecha between '$FI' and '$FF' and cod_cte = C.cod_cte";
$sqt.=" and vendedor = '$vendedor' and cod_prod = @producto and transaccion in ('36','37','38')";
$sqt.=" order by fecha desc),'') as ultima_venta,";
$sqt.="isnull((select top 1 fecha";
$sqt.=" from mpedcte where status <> 'C' and fecha between '$FI' and '$FF' and cod_cte = C.cod_cte";
$sqt.=" and vendedor = '$vendedor' and cod_prod = '$producto' and transaccion = '31'";
$sqt.=" order by fecha desc),'') as ultima_pedido,";
$sqt.="isnull((select sum(cantidad) from entysal where folio in";
$sqt.=" (select top 1 folio";
$sqt.=" from entysal where status <> 'C' and fecha between '$FI' and '$FF' and cod_cte = C.cod_cte";
$sqt.=" and vendedor = '$vendedor' and cod_prod = '$producto' and transaccion in ('36','37','38')";
$sqt.=" order by fecha desc)),0.0) as cantidad_venta,";
$sqt.="isnull((select sum(cantidad_pedida) from mpedcte where folio in";
$sqt.=" (select top 1 folio";
$sqt.=" from mpedcte where status <> 'C' and fecha between @FI and @FF and cod_cte = C.cod_cte";
$sqt.=" and vendedor = '$vendedor' and cod_prod = '$producto' and transaccion = '31'";
$sqt.=" order by fecha desc)),0.0) as cantidad_pedido,";
$sqt.="isnull((select status from pedcte where folio in";
$sqt.=" (select top 1 folio";
$sqt.=" from mpedcte where status <> 'C' and fecha between @FI and @FF and cod_cte = C.cod_cte";
$sqt.=" and vendedor = '$vendedor' and cod_prod = '$producto' and transaccion = '31'";
$sqt.=" order by fecha desc)),'') as status_pedido";
$sqt.=" FROM CLIENTES C";
$sqt.=" where vendedor = '$vendedor'";

$res=mssql_query($sqt);
...

Creo que no me he dejado ningún espacio. Las fechas SQL server, ¿las puede tomar como cadenas con el formato 'dd/mm/yyyy hh:nn'? Si no habría que cambiar las líneas en azul, por ejemplo, en formato yyyymmddhhnn serían:

$FI = '200710010000';
$FF = '200711222359';
__________________
Kelpie