Solved

Adding ISNULL to this query

Posted on 2011-09-28
4
235 Views
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
select 
			'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

0
Comment
Question by:red_75116
[X]
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
4 Comments
 
LVL 92

Accepted Solution

by:
Patrick Matthews earned 500 total points
ID: 36717945
select 
			'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

0
 

Author Comment

by:red_75116
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.
0
 

Author Closing Comment

by:red_75116
ID: 36718040
thanks!
0
 
LVL 92

Expert Comment

by:Patrick Matthews
ID: 36718046
Sorry, try:


select 
	'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

0

Featured Post

Efficient way to get backups off site to Azure

This user guide provides instructions on how to deploy and configure both a StoneFly Scale Out NAS Enterprise Cloud Drive virtual machine and Veeam Cloud Connect in the Microsoft Azure Cloud.

Question has a verified solution.

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

JSON is being used more and more, besides XML, and you surely wanted to parse the data out into SQL instead of doing it in some Javascript. The below function in SQL Server can do the job for you, returning a quick table with the parsed data.
For both online and offline retail, the cross-channel business is the most recent pattern in the B2C trade space.
Using examples as well as descriptions, and references to Books Online, show the different Recovery Models available in SQL Server and explain, as well as show how full, differential and transaction log backups are performed
This videos aims to give the viewer a basic demonstration of how a user can query current session information by using the SYS_CONTEXT function

749 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