|
|
|
SSC Veteran
      
Group: General Forum Members
Last Login: Yesterday @ 9:53 AM
Points: 239,
Visits: 446
|
|
Hi guys,
Once again it looks like Excel is the poor relation in SSIS.
I am trying to create a DataFlow task which connects to my database and runs an SQL SELECT statement into an Excel results set.
The SQL statement is as follows
SELECT OBR.cppolref, OBR.ValidFrom, S.FSASegment, S.Warning, F.Deceased, F.VIP, F.AltAddress, F.Flats, F.HEC, F.SpecialNeeds, coalesce(F.SpecialNeedsDescription,'') as 'SpecialNeedsDescription', PF.additionalElementPrice, coalesce(count(CDC.complaintref),0) + coalesce(count(CMS.complaintref),0) as 'TotComplaints', coalesce(count(CDC2.complaintref),0) + coalesce(count(CMS2.complaintref),0) as 'TotOpenComplaints', coalesce(count(CDC3.complaintref),0) + coalesce(count(CMS3.complaintref),0) as 'TotOpenFSAComplaints' FROM opsBatchRecord OBR join Segments S on S.cppolref = OBR.cppolref AND S.validfrom = OBR.Validfrom join cpfact F on F.cppolref = OBR.cppolref AND F.validFrom = OBR.ValidFrom join priceFact PF on PF.cppolref = OBR.cppolref AND PF.ValidFrom = OBR.ValidFrom left join CDCComplaints CDC on CDC.cppolref = OBR.cppolref AND CDC.ValidFrom = (SELECT Max(ValidFrom) from CDCComplaints Where Validto <= f.validto) left join CMSComplaints CMS on CMS.cppolref = OBR.cppolref left join CDCComplaints CDC2 on CDC2.cppolref = OBR.cppolref AND CDC2.ValidFrom = (SELECT Max(ValidFrom) from CDCComplaints Where Validto <= f.validto) AND CDC2.Status = 'Open' left join CMSComplaints CMS2 on CMS2.cppolref = OBR.cppolref AND CMS2.status in ('open','FSA open') left join CDCComplaints CDC3 on CDC3.cppolref = OBR.cppolref AND CDC3.ValidFrom = (SELECT Max(ValidFrom) from CDCComplaints Where Validto <= f.validto) AND CDC3.Status = 'Open' AND CDC3.FSAReportable = 1 left join CMSComplaints CMS3 on CMS3.cppolref = OBR.cppolref AND CMS3.status = 'FSA open' WHERE OBR.BatchID = 1001 Group by OBR.cppolref, OBR.ValidFrom, S.FSASegment, S.Warning, F.Deceased, F.VIP, F.AltAddress, F.Flats, F.HEC, F.SpecialNeeds, F.SpecialNeedsDescription, PF.additionalElementPrice
Firstly, SSIS seems to choke on the colaesce() statement; when I put the code into Build Query it puts the coalesce in square brackets [coalesce] and treats it as a field name which then breaks the syntax - WHY!!!!!! I have replaced the coalesce() with isnull() and it seems to be happier, but still gives me an error message "syntax error in FROM clause" when I try to parse the query. Both versions of the query work just fine in Mgmt studio
|
|
|
|
|
SSCertifiable
       
Group: General Forum Members
Last Login: Today @ 1:24 PM
Points: 6,826,
Visits: 11,950
|
|
Sorry if I am missing it, but are you running this SELECT against a SQL Server OLE DB connection or trying to run it against an Excel OLE DB connection?
__________________________________________________________________________________________________ There are no special teachers of virtue, because virtue is taught by the whole community. --Plato
Believe you can and you're halfway there. --Theodore Roosevelt
Everything Should Be Made as Simple as Possible, But Not Simpler --Albert Einstein
The significant problems we face cannot be solved at the same level of thinking we were at when we created them. --Albert Einstein
1 apple is not exactly 1/8 of 8 apples. Because there are no absolutely identical apples. --Giordy
|
|
|
|
|
SSC Veteran
      
Group: General Forum Members
Last Login: Yesterday @ 9:53 AM
Points: 239,
Visits: 446
|
|
@OPC
Sorry for the delay in answering. It was running against the OLEDB datasource (SQL server 2005). I eventually fudged it by creating the SELECT statement as a view in the database and calling that instead, filtering in the WHERE clause for the search conditions.
|
|
|
|
|
SSCertifiable
       
Group: General Forum Members
Last Login: Today @ 1:24 PM
Points: 6,826,
Visits: 11,950
|
|
It's possible something with the OLE DB driver could not infer (or the database did not return an acceptable inference) the data types output by the expressions making up the last three columns in your SELECT. You may have had some luck adding a CAST around each of those columns but I am happy you got it sorted.
__________________________________________________________________________________________________ There are no special teachers of virtue, because virtue is taught by the whole community. --Plato
Believe you can and you're halfway there. --Theodore Roosevelt
Everything Should Be Made as Simple as Possible, But Not Simpler --Albert Einstein
The significant problems we face cannot be solved at the same level of thinking we were at when we created them. --Albert Einstein
1 apple is not exactly 1/8 of 8 apples. Because there are no absolutely identical apples. --Giordy
|
|
|
|