Thursday, 15 August 2013

Join Function in SQL

Join Function in SQL

I have a query that joins about 5 tables and displays all the results. The
records show on the web application it should have around 70000 entries
however when I do this join it only displays 51000 entries in MSSQL 2008.
I was wondering how I can manipulate the join functions to display all the
70000 entries perhaps adding an outer join or an inner join? I don't have
too much experience with the join function and was hoping for someone to
edit my query for it to display all entries in those 5 tables. I know this
is a quick fix for an expert progammer and I appreciate the time and
effort in advance! Cheers
Existing Query:
select SerialNum as [Serial Number],ts_sitename As Site,(case m.Scratched
when 0 then 'Live'
when 1 then 'Free'
END) as Status, Note as Comment,
SUBSTRING(cast(EffectiveDate as char), 1, 8) AS [Effective Date Added],
SUBSTRING(cast(EffectiveDate as char), 10, 6) AS [Effective Time Added],
SUBSTRING(cast(ScratchedDate as char), 1, 8) AS [Scratched Date],
SUBSTRING(cast(ScratchedDate as char), 10, 6) AS [Scratched Time],
SUBSTRING(cast(ChangedPurgeDate as char), 1, 8) AS [Purge Date],
SUBSTRING(cast(ChangedPurgeDate as char), 10, 6) AS [Purge Time],
fl_filename as Dataset, hs_hostname,UserCode
from (((((Media m join TheSites_tab s on m.SiteId = s.ts_sitenum)
join MediaGenT g on m.MediaId = g.mg_medianum)
join TheHosts_tab h on mg_hostnum = h.hs_hostnum)
join TheFiles_tab f on mg_filenum = f.fl_filenum)
join [User] u on mg_usernum = u.UserId)
join Note n on m.NoteId = n.NoteId
where Destroyed = '0';

No comments:

Post a Comment