?
Solved

Adding ISNULL to this query

Posted on 2011-09-28
4
Medium Priority
?
249 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 93

Accepted Solution

by:
Patrick Matthews earned 2000 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 93

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

Survive A High-Traffic Event with Percona

Your application or website rely on your database to deliver information about products and services to your customers. You can’t afford to have your database lose performance, lose availability or become unresponsive – even for just a few minutes.

Question has a verified solution.

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

It is possible to export the data of a SQL Table in SSMS and generate INSERT statements. It's neatly tucked away in the generate scripts option of a database.
Windocks is an independent port of Docker's open source to Windows.   This article introduces the use of SQL Server in containers, with integrated support of SQL Server database cloning.
Via a live example combined with referencing Books Online, show some of the information that can be extracted from the Catalog Views in SQL Server.
Via a live example, show how to extract insert data into a SQL Server database table using the Import/Export option and Bulk Insert.

718 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