We help IT Professionals succeed at work.
Get Started

SQL string from 3 cases

Last Modified: 2012-05-11
I have a function that is working and builds a string that is returned

What I need is to build a string that reads

'Error: Invalid '  And whichever variable or variables are = 'N'

Example...If all are invalid or = 'N'

@Output = 'Invalid or missing policyNumber,  IssuerName, CADate'

If ONLY CADate is invalid
@Output = 'Invalid or missing CADate'

ALTER FUNCTION [dbo].[uf_ucc_structured_WithCA] (@DealID int) 

	Declare @policyNumber varchar(40)
	Declare @IssuerName varchar(100)
	Declare @CADate varchar(30)
	Select	@policyNumber = x.AnnnuitantPolicyNumber,
			@IssuerName   = x.IssuerName,
			@CADate		  = x.EventDate	   
			From	( Select IsNull(pd.AnnuitantPolicyNumber,'N') AnnnuitantPolicyNumber
						,IsNull(i.IssuerName, 'N') IssuerName
						,case when pe.[EventData] is null then 'N' else dbo.FormatDateTime(pe.[EventData], 'STANDARD') end eventDate
						 from crmprod_01.dbo.P_Deals pd 
								left join proc_ss.dbo.p_issuers i on pd.IssuerID = i.IssuerID
								left join crmprod_01.dbo.p_Events_Table pe on (pd.DealID = pe.dealID  and pe.EventTypeID = 84)
								where pd.DealID =@dealID) x
	DECLARE @Output VARCHAR(8000)
		SET		@Output =	@policyNumber + ' , ' + @IssuerName + ' , ' + @CADate
	RETURN @Output

Open in new window

Watch Question
Software Engineer
This problem has been solved!
Unlock 1 Answer and 10 Comments.
See Answer
Why Experts Exchange?

Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.

Jim Murphy
Programmer at Smart IT Solutions

When asked, what has been your best career decision?

Deciding to stick with EE.

Mohamed Asif
Technical Department Head

Being involved with EE helped me to grow personally and professionally.

Carl Webster
CTP, Sr Infrastructure Consultant
Ask ANY Question

Connect with Certified Experts to gain insight and support on specific technology challenges including:

  • Troubleshooting
  • Research
  • Professional Opinions
Did You Know?

We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE