我想将此 SQL 查询转换为 LAravel SQL Builder 但我不知道为什么我已经阅读了 laravel 文档但我找不到答案
SQL查询:
SELECT
CONTRATO,
CASE WHEN RAZONSOCIAL IS NULL OR RAZONSOCIAL = ''
THEN ISNULL(PATERNO, '') + ' ' + ISNULL(MATERNO, '') + ' ' + ISNULL(NOMBRES, '')
ELSE RAZONSOCIAL
END AS NOMBRE,
CADENAUNICA,
CLAVERASTREO,
FECHAASIENTO,
IDGARANTIA,
RutaGuardadoPDF,
RutaGuardadoXML
FROM
DEUDORES AS D
LEFT JOIN
RELACIONES AS R
ON D.RUGID = R.RUGID
WHERE CONTRATO = 'A1412015'
AND D.AcreedorId IN (
SELECT
ACREEDORID
FROM
[MasterCLI].[dbo].[Rrug]
WHERE FIDEICOMISOID = 5
)
我在 laravel 中做这个代码
$AcreedorFide = \DB::connection('sqlsrv')
->table('Rrug')
->select('AcreedorID')
->where('Fideicomiso', $fideicomiso)
->get();
$BoletaRUG = \DB::connection('RUG')
->table('Deudores')
->select(
'Contrato',
'CadenaUnica',
'ClaveRastreo',
'FechaAsiento',
'IdGarantia',
'RutaGuardadoPDF',
'RutaGuardadoXML'
)
->select(DB::raw('CASE WHEN RAZONSOCIAL IS NULL'))
->leftJoin('Relaciones','Deudores.RugId', '=', 'Relaciones.RugId')
->where('Contrato', $Contrato)
->wherein('Acreedorid', $AcreedorFide)
->get();