Click here to monitor SSC
SQLServerCentral is supported by Red Gate Software Ltd.
 
Log in  ::  Register  ::  Not logged in
 
 
 
        
Home       Members    Calendar    Who's On


Add to briefcase

SSIS2005: DataFlow Task from OLE DB Source to Excel File Destination Expand / Collapse
Author
Message
Posted Wednesday, January 2, 2013 8:59 AM
SSC-Addicted

SSC-AddictedSSC-AddictedSSC-AddictedSSC-AddictedSSC-AddictedSSC-AddictedSSC-AddictedSSC-Addicted

Group: General Forum Members
Last Login: Yesterday @ 12:16 AM
Points: 461, Visits: 693
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
Post #1401888
Posted Thursday, January 3, 2013 5:37 PM


SSCertifiable

SSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiable

Group: General Forum Members
Last Login: Yesterday @ 8:51 PM
Points: 7,140, Visits: 12,763
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
Post #1402624
Posted Monday, January 7, 2013 1:54 AM
SSC-Addicted

SSC-AddictedSSC-AddictedSSC-AddictedSSC-AddictedSSC-AddictedSSC-AddictedSSC-AddictedSSC-Addicted

Group: General Forum Members
Last Login: Yesterday @ 12:16 AM
Points: 461, Visits: 693
@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.

Post #1403476
Posted Monday, January 7, 2013 8:02 AM


SSCertifiable

SSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiable

Group: General Forum Members
Last Login: Yesterday @ 8:51 PM
Points: 7,140, Visits: 12,763
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
Post #1403629
« Prev Topic | Next Topic »

Add to briefcase

Permissions Expand / Collapse