Left Outer Join for CF write CSV question
I'm attempting my first Left Out Join in trying to output data fields in MS Access to a CSV file for downloading...
I may need to be in a different forum since this is a CF Query. Please someone let me know if I need to post this somewhere else.
I have several tables to call from. One of the tables (ewc) contains several different ID numbers and the other tables also contain one or more of these same ID numbers.
I hope I'm right in assuming that I need to do a Left Outer Join, basing the data pulled on the ID numbers in the one table to the corresponding ID fields in the other tables.
I'm getting an error somewhere in the query code (but am including the whole code on the page.
Thanks for anyone's help.
- e
PS: I plan to use cfqueryparam within the query instead of a 'straight query' for the final. Just am trying to go simple so as to test the whole code before going public...
------------------------------------------------------
<cfquery name = "getpredata" datasource = "M_data">
SELECT
ewc.EWCsID, ewc.StID, ewc.SC01, ewc.SC02, ewc.EWCscNumber, sc.EWCscNumber, sc.SC01, sc.SC02, sc.Scme, sc.Level, st.EWCstID, st.EWCscNumber, st.LName, st.FName, st.Et, st.Ge, st.Be, st.Lat, st.S8P, st.D9P, st.B7D, st.PreW, st.PreH, st.PreWHDate, st.HTName
FROM
((ewc_table ewc
LEFT OUTER JOIN
sc_table sc ON ewc.EWCscNumber = sc.EWCscNumber)
LEFT OUTER JOIN
pers_table st ON ewc.EWCsID = st.EWCsID)
WHERE
sc.Level = active
ORDER By
sc.EWCscNumber
</cfquery>
<cfif getpredata.recordcount GTE 66000>
Too many records for download. Please contact Website Support.
<cfelse>
<cffile action="write"
file="D:\website.com\mt\download\mtpredata.csv"
output="SSC,SC 01,SC 02,ST ID,Last Name,First Name,ET,GE,BE,LAT,S 8 P,D 9 P,B 7 D,Pre W,Pre H,Pre WH Date,HT Name"
addnewline="yes">
<cfoutput>
<cfloop query="getpredata">
<cffile action="append"
file="D:\website.com\mt\download\mtpredata.csv"
output="#TRIM(Scme)# , #TRIM(SC01)# , #TRIM(SC02)# , #TRIM(StID)# , #TRIM(LName)# , #TRIM(FName)# , #TRIM(Et)# , #TRIM(Ge)# , #TRIM(Be)# , #TRIM(Lat)# , #TRIM(S8P)# , #TRIM(D9P)# , #TRIM(B7D)# , #TRIM(PreW)# , #TRIM(PreH)# , #TRIM(PreWHDate)# , #TRIM(HTName)#"
addnewline="yes">
</cfloop>
</cfoutput>
<cflocation url="www.website.com/download/mtpredata.csv">
</cfif>
