We use the projected correlation function w_p(r_p) of a volume-limited subsample of the Sloan Digital Sky Survey (SDSS) main galaxy redshift catalogue to measure the halo occupation distribution (HOD) of the galaxies of the sample. Simultaneously, we allow the cosmology to vary within cosmological constraints imposed by cosmic microwave background experiments in a Lambda-CDM model. We find that combining w_p(r_p) for this sample alone with the observations by WMAP, ACBAR, CBI and VSA can provide one of the most precise techniques available to measure cosmological parameters. For a minimal flat six-parameter Lambda-CDM model with an HOD with three free parameters, we find Omega_m=0.278^{+0.027}_{-0.027}, sigma_8=0.812^{+0.028}_{-0.027}, and H_0=69.8^{+2.6}_{-2.6}km s^{-1} Mpc^{-1}; these errors are significantly smaller than from CMB alone and similar to those obtained by combining CMB with the large-scale galaxy power spectrum assuming scale-independent bias. The corresponding HOD parameters describing the minimum halo mass and the normalization and cut-off of the satellite mean occupation are M_min=(3.03^{+0.36}_{-0.36})x 10^{12} h^{-1} M_sun, M_1 = (4.58^{+0.60}_{-0.60})x 10^{13} h^{-1} M_sun, and kappa=4.44^{+0.51}_{-0.69}. When more parameters are added to the HOD model, the error bars on the HOD parameters increase because of degeneracies, but the error bars on the cosmological parameters do not increase greatly. Similar modeling for other galaxy samples could reduce the statistical errors on these results, while more thorough investigations of the cosmology dependence of nonlinear halo bias and halo mass functions are needed to eliminate remaining systematic uncertainties, which may be comparable to statistical uncertainties.