4

I have an SQL query inside a SQL Server Integration Services (SSIS) package where the preview shows the column order correctly, however the actual output uses a different column order.

This is exported to a .csv file for import into another application and needs to be in a specific order.

I need the Date column first, which shows up that way when I preview the data output in the OLE DB Source Editor window; however, when I click on the "Columns" to display their order it shows them outputing in the last position, which is what they do.

Here is the SQL query:

DECLARE @now DATETIME;
SET @now = GETDATE()-45;
SELECT CONVERT(VARCHAR(8), [ORDERS].[STARDAT], 10) AS [MM-DD-YY], [ORDERS].[CLIENTID], 
 [ORDERS].[SAMPNAME], [ANALYTES].[OP10AN], [RESULTS].[FINAL]
FROM [ORDERS], [RESULTS], [RUNS], [ANALYTES], [SamNam]
WHERE [ORDERS].[sampname] = [SamNam].[SName]
 AND [RUNS].[RUNSTS]= 'D' 
 AND [RUNS].[COMPDATE]>@now 
 AND [ORDERS].[SAMPTYPE] IS NULL 
 AND [ORDERS].[ORDNO] NOT IN (308333,308334) 
 AND [ORDERS].[CLIENTID] <> 'Ind Waste' 
 AND [RESULTS].[ORDNO]=[ORDERS].[ORDNO] 
 AND [RESULTS].[RUNNO]=[RUNS].[RUNNO] 
 AND [RESULTS].[ANALPRINT]= 'Y' 
 AND [ANALYTES].[SINONYM] =[RESULTS].[SINONYM] 
 AND [ANALYTES].[TESTCODE] =[RESULTS].[TESTCODE] 
 AND [ANALYTES].[OP10AN] IS NOT NULL
ORDER BY [ORDERS].[ordno];

Any input into why the query is getting turned around?

Hannah Vernon
71.1k22 gold badges178 silver badges324 bronze badges
asked Oct 22, 2012 at 16:49
1
  • Is that the only field out of the specified order? Commented Oct 22, 2012 at 16:56

1 Answer 1

4

In the Columns page on the OLE DB Source, you can use the check boxes beside the columns to change the order.

The columns are added to the output in the order in which they get checked, so what you need to do is uncheck all the columns, and then check them again in the correct order.

Downstream data flow tasks will want to update themselves because the column mappings "broke", but this shouldn't be a big issue to fix.

answered Oct 22, 2012 at 17:41
3
  • Thank you Jon, That id correct that part of the output; however, now the flatfile still contains the incorrect mapping from the previous run. I get the following error now: Package Validation Error Error at Data Flow Task [SSIS.Pipeline]: input column "CLIENTID" (165) has lineage ID 20 that was not previously used in the Data Flow task. Error at Data Flow Task [SSIS.Pipeline]: "component "Flat File Destination" (154) failed validation and returned validation status "VS_NEEDSNEWMETADATA". Commented Oct 22, 2012 at 18:16
  • 1
    @Akomarek: You should just have to no-op edit the Flat File Destination, so it can remap the columns as I mentioned. Commented Oct 22, 2012 at 18:27
  • 8 years later this helped me out greatly! Commented Dec 9, 2020 at 16:40

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.