Adding ISNULL to this query

Posted on 2011-09-28
Last Modified: 2012-06-27
I have this query which is returning a NULL value instead of the values I need.  I need to add a ISNULL to the first line, but with all the trims, lefts, I am having trouble.

Where exactly would that go?  It needs to be attached to dd.ODJCJOB
			'Job: ' + LEFT(LTRIM(dd.ODJCJOB) + SPACE(16), 16) +
			'Cost Code: ' + LEFT(LTRIM(dd.ODJCPHS) + SPACE(16), 16) + 
			'Amount: ' + LEFT(LTRIM(STR(dd.ODAMT, 14, 2)) + SPACE(16), 16)
		from [ADCData].dbo.MASTER_APM_RECORD_2 dd 
		where dd.ODINV = '061711' and dd.ODVND = 'ASSURANTEM'

Open in new window

Question by:red_75116
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
LVL 92

Accepted Solution

Patrick Matthews earned 500 total points
ID: 36717945
			'Job: ' + COALESCE(LEFT(LTRIM(dd.ODJCJOB), '') + SPACE(16), 16) +
			'Cost Code: ' + COALESCE(LEFT(LTRIM(dd.ODJCPHS), '') + SPACE(16), 16) + 
			'Amount: ' + COALESCE(LEFT(LTRIM(STR(dd.ODAMT, 14, 2)), '') + SPACE(16), 16)
		from [ADCData].dbo.MASTER_APM_RECORD_2 dd 
		where dd.ODINV = '061711' and dd.ODVND = 'ASSURANTEM'

Open in new window


Author Comment

ID: 36717991
i get this error when I run this

Msg 245, Level 16, State 1, Line 1
Conversion failed when converting the varchar value 'Job: ' to data type int.

Author Closing Comment

ID: 36718040
LVL 92

Expert Comment

by:Patrick Matthews
ID: 36718046
Sorry, try:

	'Job: ' + LEFT(LTRIM(COALESCE(dd.ODJCJOB, '')) + SPACE(16), 16) +
		'Cost Code: ' + LEFT(LTRIM(COALESCE(dd.ODJCPHS, '')) + SPACE(16), 16) + 
		'Amount: ' + LEFT(LTRIM(STR(COALESCE(dd.ODAMT, ''), 14, 2)) + SPACE(16), 16)
	from [ADCData].dbo.MASTER_APM_RECORD_2 dd 
	where dd.ODINV = '061711' and dd.ODVND = 'ASSURANTEM'

Open in new window


Featured Post

Salesforce Made Easy to Use

On-screen guidance at the moment of need enables you & your employees to focus on the core, you can now boost your adoption rates swiftly and simply with one easy tool.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Why is this different from all of the other step by step guides?  Because I make a living as a DBA and not as a writer and I lived through this experience. Defining the name: When I talk to people they say different names on this subject stuff l…
Slowly Changing Dimension Transformation component in data task flow is very useful for us to manage and control how data changes in SSIS.
Using examples as well as descriptions, and references to Books Online, show the documentation available for datatypes, explain the available data types and show how data can be passed into and out of variables.
Viewers will learn how to use the SELECT statement in SQL to return specific rows and columns, with various degrees of sorting and limits in place.

623 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question