SSMS Job: Email Out Stored Procedure Not Exporting Records Where NULL in Field

Hello,
Created a stored procedure that pulls a query.  In the query, one of the fields, called companyCode, can have char, numbers, char&numbers or null data.  
Example the field could contain:   A1234  or 1234 or NULL
I don't have access to the field definition.
I created a Job to email out the stored procedure.  When I run the query there are 1415 records returned.  When I execute the stored procedure there are 1415 records returned.  When I run the job there are only 1118 records returned.
I noticed when I don't do a sort by "companyCode" then I get 2 records.  
When I do a sort by companyCode DESC I get 1118 records.  The ones that don't show up are the NULL ones.

Working with SSMS - SQL 2008 R2

Here's the query
SELECT  org_cst_key,
            org_name,
            org_ogt_code,
            org_group_code_ext,
            org_companycode,
            co_organization  WITH (NOLOCK)
            WHERE org_name != N'Enter Value'
      ORDER BY org_companycode DESC
Here's the job
EXEC msdb.dbo.sp_send_dbmail
@profile_name = 'Database Mail',
@recipients='jack@xxx.org',
@from_address='datbasemail@xxx.org',
@subject='Member Companies Extract',
@body='Attached is the Member Companies. ',
@query ='exec dbo.member_companies',
@query_attachment_filename = 'MemberCompanies.csv',
@execute_query_database = 'nf2014',
@attach_query_result_as_file = 1,
@query_result_header = 1,
@query_result_width = 32767,
@query_result_separator = '|' ,
@query_result_no_padding =1;
LVL 2
jshesekAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

ste5anSenior DeveloperCommented:
Post the entire stored procedure.. your code snippet is incomplete.

Well, I would drop the NOLOCK hint, cause it maybe the cause for your problem.
0
jshesekAuthor Commented:
USE [nf2014]
GO

SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO

ALTER PROCEDURE [dbo].[member_companies]
      
AS
BEGIN
      SET NOCOUNT ON;

    SELECT DISTINCT org_cst_key,
            org_name,
            org_ogt_code,
            org_group_code_ext,
            org_companycode
            FROM
            co_organization  WITH (NOLOCK)  
            WHERE org_name != N'Enter Value'
      ORDER BY org_cst_naic_code_ext DESC
END
0
jshesekAuthor Commented:
When I run the stored procedure the data all shows up.  1145 records
0
Cloud Class® Course: Python 3 Fundamentals

This course will teach participants about installing and configuring Python, syntax, importing, statements, types, strings, booleans, files, lists, tuples, comprehensions, functions, and classes.

jshesekAuthor Commented:
Took the NoLock out and didn't change the emailed result
0
jshesekAuthor Commented:
Figured it out.  When it was hitting a date field the job was blowing up.  So I formatted the output to a VARCHAR
CONVERT(VARCHAR,join_date,101) as join_date
All the data came through.
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
jshesekAuthor Commented:
I solved the issue
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft SQL Server 2008

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.