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

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,
            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',
@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;
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

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.
jshesekAuthor Commented:
USE [nf2014]


ALTER PROCEDURE [dbo].[member_companies]

    SELECT DISTINCT org_cst_key,
            co_organization  WITH (NOLOCK)  
            WHERE org_name != N'Enter Value'
      ORDER BY org_cst_naic_code_ext DESC
jshesekAuthor Commented:
When I run the stored procedure the data all shows up.  1145 records
Acronis True Image 2019 just released!

Create a reliable backup. Make sure you always have dependable copies of your data so you can restore your entire system or individual files.

jshesekAuthor Commented:
Took the NoLock out and didn't change the emailed result
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.

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
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.