CREATE FUNCTION GetConfigID @CL ID INT
RETURNS INT AS
BEGIN
DECLARE @SConfigIdID INT
SET @SConfigIdID = (SELECT ConC. ID FROM tblContract CN
INNER JOIN tblClient CL ON CN.CLIENT_ID = CL.ID INNER JOIN tblCar CR ON CN.CAR_ID = CR.ID
INNER JOIN tblConfigCar ConC ON CR.CONFIG_MODEL_ID = ConC. ID WHERE Cl.ID = @CL_ID)
RETURN @ConfigldID
END
GO