Link to home
Start Free TrialLog in
Avatar of GPSPOW
GPSPOWFlag for United States of America

asked on

Output Stored Procedure data to Text File

Here is the end of the Stored Procedure I have.  It has gone through many steps to create temporary values in the "Final Calculation".  After the "Final Calculation" is done, the results are outputted to the screen.

I want to send these values to a text or csv file.

Here is the code:

/* FINAL CALCULATION */
      SET @Denominator = (SELECT COUNT(VisitID) FROM #StrokePopulation)
      SET @Numerator = (SELECT COUNT(VisitID) FROM #Numerator)
      SET @Exclusions = (SELECT COUNT(VisitID) FROM #Exclusions)

/* Output for Attestation */
      SELECT
            @MeasureNumberIdentifier AS 'Measure'
         ,@ReportName AS 'Report Name'
         ,@Denominator AS 'Denominator'
         ,@Numerator AS 'Numerator'
         ,@Exclusions AS 'Exclusions'

/* Output Detail for patients meeting Performance Numerator */
IF @Detail = 'Y'
      SELECT 'Yes' AS [Meets Measure],*
      FROM #Numerator

Is "BCP" an option?

thanks

Glen
SOLUTION
Avatar of Zberteoc
Zberteoc
Flag of Canada image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
If you're using SQL Server 2005 or later, you might consider putting it in an SSIS package and running that. Personally I find that a lot easier than using BCP. You can add a Dataflow task to the ControlFlow window, and an OLE DB source and a Flat File destination in the task. The source is your procedure and the dest. is your .csv file.

Hth   - Mike
Avatar of GPSPOW

ASKER

Do I need to qualify the "@" variables  ( @MeasureNumberIdentifier, @Numerator, etc) to send to the text file?

or

Do I need to store the output variables into a table and then use BCP to export the table to the text file?

Glen
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of GPSPOW

ASKER

Our server is down now.

As soon as the administrator reboots it, I will try out your suggestion.

Thanks

Glen
ASKER CERTIFIED SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of GPSPOW

ASKER

I like all the solutions.

Mark's was exactly what I was looking for.

Thanks

glen