Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2008 Forums
 Transact-SQL (2008)
 Appending to field in a switch statement

Author  Topic 

ATG
Starting Member

35 Posts

Posted - 2010-08-11 : 14:23:05
I'm trying to append to a field using a switch. What I want it to do is check several fields for a data, and if they dont have them, append a message. Here is my sample code. I think I'm close but can't seem to get it.

ALTER PROCEDURE CheckSubcontractField
@Company varchar(10),
@Job varchar(10),
@SL varchar(10)
as

update SLHD set SLHD.udVerifyField=
(
select CASE
when (SLHD.PayTerms is null) then SLHD.udVerifyField + ('Pay Terms')
when (JCJMPM.udSuperintendent is null) then SLHD.udVerifyField + ('Superintendent not entered')
when (JCJMPM.ProjectMgr is null) then SLHD.udVerifyField + ('PM not entered')
when (JCJMPM.udPrjAcct is null) then SLHD.udVerifyField + ('PA not entered')
end
)

from JCJMPM JCJMPM (Nolock)
LEFT JOIN PMPM PM (Nolock) on PM.ContactCode=JCJMPM.ProjectMgr and PM.VendorGroup=JCJMPM.VendorGroup
LEFT JOIN PMPM Super (Nolock) on Super.ContactCode=JCJMPM.udSuperintendent and Super.VendorGroup=JCJMPM.VendorGroup
LEFT JOIN PMPM PA (Nolock) on PA.ContactCode=JCJMPM.udPrjAcct and PA.VendorGroup=JCJMPM.VendorGroup
LEFT JOIN SLHDPM SLHD (Nolock) on SLHD.Job=JCJMPM.Job and SLHD.JCCo=JCJMPM.JCCo and SLHD.VendorGroup=JCJMPM.VendorGroup
LEFT JOIN PMSS PMSS (Nolock) on PMSS.SL=SLHD.SL and PMSS.VendorGroup=SLHD.VendorGroup

where (JCJMPM.Job=@Job and JCJMPM.JCCo=@Company and SLHD.SL=@SL) and (JCJMPM.udSuperintendent is null)

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2010-08-11 : 14:35:55
quote:
Originally posted by ATG

I'm trying to append to a field using a switch. What I want it to do is check several fields for a data, and if they dont have them, append a message. Here is my sample code. I think I'm close but can't seem to get it.

ALTER PROCEDURE CheckSubcontractField
@Company varchar(10),
@Job varchar(10),
@SL varchar(10)
as

update SLHD set SLHD.udVerifyField=SLHD.udVerifyField +
CASE
when (SLHD.PayTerms is null) then 'Pay Terms' ELSE '' END +
CASE when (JCJMPM.udSuperintendent is null) then 'Superintendent not entered' ELSE '' END +
CASE when (JCJMPM.ProjectMgr is null) then 'PM not entered' ELSE '' END + CASE when (JCJMPM.udPrjAcct is null) then 'PA not entered' ELSE '' END


from JCJMPM JCJMPM (Nolock)
LEFT JOIN PMPM PM (Nolock) on PM.ContactCode=JCJMPM.ProjectMgr and PM.VendorGroup=JCJMPM.VendorGroup
LEFT JOIN PMPM Super (Nolock) on Super.ContactCode=JCJMPM.udSuperintendent and Super.VendorGroup=JCJMPM.VendorGroup
LEFT JOIN PMPM PA (Nolock) on PA.ContactCode=JCJMPM.udPrjAcct and PA.VendorGroup=JCJMPM.VendorGroup
LEFT JOIN SLHDPM SLHD (Nolock) on SLHD.Job=JCJMPM.Job and SLHD.JCCo=JCJMPM.JCCo and SLHD.VendorGroup=JCJMPM.VendorGroup
LEFT JOIN PMSS PMSS (Nolock) on PMSS.SL=SLHD.SL and PMSS.VendorGroup=SLHD.VendorGroup

where (JCJMPM.Job=@Job and JCJMPM.JCCo=@Company and SLHD.SL=@SL) and (JCJMPM.udSuperintendent is null)



may be you're looking at above tweak

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page

vijayisonly
Master Smack Fu Yak Hacker

1836 Posts

Posted - 2010-08-11 : 14:57:50
Also remove the NOLOCK table hint. It applies only to SELECT.
Go to Top of Page

ATG
Starting Member

35 Posts

Posted - 2010-08-11 : 15:42:28
Thanks! That almost worked, but I was able to tweak it so that it does.

I changed "update SLHD set SLHD.udVerifyField=SLHD.udVerifyField +" to "update SLHD set SLHD.udVerifyField="
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2010-08-12 : 14:06:41
ok great

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page
   

- Advertisement -