SQL Conditional field return

Hi,

I have the following SQL query below.

Basically it only returns if the two conditions are met:
fn_rbac_PackageStatusDistPointsSumm.State = 1 and
                        vSMS_DistributionDPStatus.MessageCategory = 76      

So how can I change it so that if vSMS_DistributionDPStatus.MessageCategory = 76 it
returns vSMS_DistributionDPStatus.InsString3 for that column

however it the vSMS_DistributionDPStatus.MessageCategory <> 76
the it returns a ' ' for that field. (So I don't get its contents in
this case).

/*      
==============================================
Check the progress of distributing packages
==============================================

*/

Declare @UserSIDs nvarchar(8)

declare @current_time as nvarchar(20)

set @current_time = convert(varchar, getdate(), 3) + ' ' + convert(varchar, getdate(), 24)
Set @UserSIDs = 'Disabled'

select fn_rbac_PackageStatusDistPointsSumm.PackageID,
	   v_Package.Name as 'Package Name',
      'Package Type (Text)' =
		Case
			when v_Package.PackageType = 0 Then 'Software Distribution Package'
			when v_Package.PackageType = 3 Then 'Driver Package'
			when v_Package.PackageType = 4 Then 'Task Sequence Package'
			when v_Package.PackageType = 5 Then 'Software Update Package'
			when v_Package.PackageType = 6 Then 'Device Setting Package'
			when v_Package.PackageType = 7 Then 'Virtual Package'
			when v_Package.PackageType = 8 Then 'Application'
			when v_Package.PackageType = 257 Then 'Image Package'
			when v_Package.PackageType = 258 Then 'Boot Image Package'
			when v_Package.PackageType = 259 Then 'Operating System Install Package'
		Else
			'Unknown'
		End,
		vSMS_DistributionDPStatus.Name as 'Distribution Point',
		vSMS_DistributionDPStatus.InsString3 as 'Percent Complete',
		@current_time as 'Current Time'
		from fn_rbac_PackageStatusDistPointsSumm(@UserSIDs) INNER JOIN
                      vSMS_DistributionDPStatus ON 
                      fn_rbac_PackageStatusDistPointsSumm.PackageID = vSMS_DistributionDPStatus.ObjectID 
                      INNER JOIN
                      v_Package ON fn_rbac_PackageStatusDistPointsSumm.PackageID = v_Package.PackageID
		  where fn_rbac_PackageStatusDistPointsSumm.State = 1 and 
				vSMS_DistributionDPStatus.MessageCategory = 76

Open in new window

LVL 1
whorsfallAsked:
Who is Participating?
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.

Jim HornMicrosoft SQL Server Developer, Architect, and AuthorCommented:
>change it so that
   if vSMS_DistributionDPStatus.MessageCategory = 76 it returns vSMS_DistributionDPStatus.InsString3
   it the vSMS_DistributionDPStatus.MessageCategory <> 76 the it returns a ' ' for that field.

SELECT blah, blah, blah, 
   CASE vSMS_DistributionDPStatus.MessageCategory  
      WHEN 76 THEN vSMS_DistributionDPStatus.InsString3 
      ELSE ' ' END, 
... blah, blah, blah..

Open in new window

0
Vitor MontalvãoMSSQL Senior EngineerCommented:
however it the vSMS_DistributionDPStatus.MessageCategory <> 76
 the it returns a ' ' for that field. (So I don't get its contents in

That would never happen with your query because it only returns  vSMS_DistributionDPStatus.MessageCategory = 76 so we can always vSMS_DistributionDPStatus.InsString3 without testing the if vSMS_DistributionDPStatus.MessageCategory = 76
0

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

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.