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 12»»

SQL Server Agent job running query only sends half of the results to file Expand / Collapse
Author
Message
Posted Wednesday, October 10, 2012 7:52 AM
Valued Member

Valued MemberValued MemberValued MemberValued MemberValued MemberValued MemberValued MemberValued Member

Group: General Forum Members
Last Login: Friday, May 17, 2013 10:07 AM
Points: 59, Visits: 663
I have an SQL Server Agent job running every day at 9am to run a query and using the Advanced tab in the specific step to run the query I send the output of the query to a CSV file. However, when checking the CSV file, only half of the results of the query display.

When I run the query itself outside of the job and save the results to a CSV file, the whole results show.

Any help greatly appreciated.
Post #1370928
Posted Wednesday, October 10, 2012 8:13 AM
SSC Eights!

SSC Eights!SSC Eights!SSC Eights!SSC Eights!SSC Eights!SSC Eights!SSC Eights!SSC Eights!

Group: General Forum Members
Last Login: Today @ 6:23 AM
Points: 852, Visits: 2,100
can you provide the below details.

are using excel to open the csv file?

what is the sql server and office version?

approximate no of rows for 2 or 3 days


Regards
Durai Nagarajan
Post #1370946
Posted Wednesday, October 10, 2012 8:22 AM
Valued Member

Valued MemberValued MemberValued MemberValued MemberValued MemberValued MemberValued MemberValued Member

Group: General Forum Members
Last Login: Friday, May 17, 2013 10:07 AM
Points: 59, Visits: 663
durai nagarajan (10/10/2012)
can you provide the below details.

are using excel to open the csv file?

what is the sql server and office version?

approximate no of rows for 2 or 3 days


I save it as a CSV file on the server to a folder on the network then open it using Excel on my PC as the server does not have Excel.

The version of SQL server is 2008 r2 and I then use Excel 2007 on my PC to open the file.

It should show roughly around 130 rows but only outputs roughly 50.. then ends with (null)
Post #1370957
Posted Wednesday, October 10, 2012 11:42 PM


SSCrazy

SSCrazySSCrazySSCrazySSCrazySSCrazySSCrazySSCrazySSCrazy

Group: General Forum Members
Last Login: Tuesday, March 26, 2013 8:41 AM
Points: 2,562, Visits: 3,451
is it started happeinig at sudden ?
and
are you using same location for CSV file by both the job and manual process? because there could be space issue




-------Bhuvnesh----------
While 1 = 1 (Learning SQL....)
Click to get fast response of your post
Post #1371218
Posted Thursday, October 11, 2012 1:51 AM
SSC Journeyman

SSC JourneymanSSC JourneymanSSC JourneymanSSC JourneymanSSC JourneymanSSC JourneymanSSC JourneymanSSC Journeyman

Group: General Forum Members
Last Login: Yesterday @ 7:41 AM
Points: 81, Visits: 859
use this in the job step while executing


EXEC MSDB.DBO.SP_SEND_DBMAIL
@PROFILE_NAME = @MPOFILENAME,
@RECIPIENTS = @MRECIPIENTS,
@COPY_RECIPIENTS = @MRECIPIENTS_CC,
@QUERY = @MQUERY,
@SUBJECT = @MPROFILEDESC,
@attach_query_result_as_file = 1,
@query_attachment_filename = 'myfile.csv'
Post #1371253
Posted Thursday, October 11, 2012 2:17 AM
Valued Member

Valued MemberValued MemberValued MemberValued MemberValued MemberValued MemberValued MemberValued Member

Group: General Forum Members
Last Login: Friday, May 17, 2013 10:07 AM
Points: 59, Visits: 663
Bhuvnesh (10/10/2012)
is it started happeinig at sudden ?
and
are you using same location for CSV file by both the job and manual process? because there could be space issue





I've only just started trying to do this so I'm not sure.

There isn't a space issue in the folder I'm saving to as the output data is only small and I don't save anything else there.
Post #1371270
Posted Thursday, October 11, 2012 2:18 AM
Valued Member

Valued MemberValued MemberValued MemberValued MemberValued MemberValued MemberValued MemberValued Member

Group: General Forum Members
Last Login: Friday, May 17, 2013 10:07 AM
Points: 59, Visits: 663
mahesh.dasoni (10/11/2012)
use this in the job step while executing


EXEC MSDB.DBO.SP_SEND_DBMAIL
@PROFILE_NAME = @MPOFILENAME,
@RECIPIENTS = @MRECIPIENTS,
@COPY_RECIPIENTS = @MRECIPIENTS_CC,
@QUERY = @MQUERY,
@SUBJECT = @MPROFILEDESC,
@attach_query_result_as_file = 1,
@query_attachment_filename = 'myfile.csv'


I'll give this a go now, thanks
Post #1371271
Posted Thursday, October 11, 2012 4:40 AM
Valued Member

Valued MemberValued MemberValued MemberValued MemberValued MemberValued MemberValued MemberValued Member

Group: General Forum Members
Last Login: Friday, May 17, 2013 10:07 AM
Points: 59, Visits: 663
mahesh.dasoni (10/11/2012)
use this in the job step while executing


EXEC MSDB.DBO.SP_SEND_DBMAIL
@PROFILE_NAME = @MPOFILENAME,
@RECIPIENTS = @MRECIPIENTS,
@COPY_RECIPIENTS = @MRECIPIENTS_CC,
@QUERY = @MQUERY,
@SUBJECT = @MPROFILEDESC,
@attach_query_result_as_file = 1,
@query_attachment_filename = 'myfile.csv'


I added this, but currently the job is failing with error:

'Executed as user: NT AUTHORITY\SYSTEM. Must declare the scalar variable @MPROFILENAME"
Post #1371344
Posted Thursday, October 11, 2012 6:11 AM
SSC Journeyman

SSC JourneymanSSC JourneymanSSC JourneymanSSC JourneymanSSC JourneymanSSC JourneymanSSC JourneymanSSC Journeyman

Group: General Forum Members
Last Login: Yesterday @ 7:41 AM
Points: 81, Visits: 859





For Database what profile name who have made mention that.

EXEC MSDB.DBO.SP_SEND_DBMAIL
@PROFILE_NAME = 'XYZ',
@RECIPIENTS = 'test@gmail.com',
@COPY_RECIPIENTS = 'test1@gmail.com',
@body= 'Job successfull',
@SUBJECT = 'This is for test',
@attach_query_result_as_file = 1,
@query_attachment_filename = 'myfile.csv'
Post #1371404
Posted Thursday, October 11, 2012 7:33 AM
Valued Member

Valued MemberValued MemberValued MemberValued MemberValued MemberValued MemberValued MemberValued Member

Group: General Forum Members
Last Login: Friday, May 17, 2013 10:07 AM
Points: 59, Visits: 663
Sorry, I didn't know what this stored proc was, I've looked more into it now and it's not what I want. I do not want the results emailed to me, I just want them to save to a CSV file. The problem I am having is that only half the results are showing. I'm currently trying BCP to see if that shows all results of the query.
Post #1371473
« Prev Topic | Next Topic »

Add to briefcase 12»»

Permissions Expand / Collapse