Sql with switch

I am looking for query for followng  ( I need the query for both Sql server and Oracle)
    There are Project  and Document tables
         Project has projectName, projectNo fileds
         Document has DocuemntNo, DocRevision,  projectNo

       The tables join with    Project.ProjectNo = Document.ProjectNo

    I need to get the ProjectName, DocumentNo, VersionNo

    But if versionNo  = 0  return Blank as VersionNo  else return  "\Ver" & VersionNo padded with five zeros

      Example result rows are
           VersionNo = 0
            Proj1, Doc1 , Blank
          VersionNo = 1
            Proj1,Doc1, \Ver00001
Sam OZAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

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.

Ryan ChongBusiness Systems Analyst , ex-Senior Application EngineerCommented:
try like:

case when VersionNo = 0 then '' else '\Ver' + right('00000' + cast(VersionNo as varchar), 5) end VersionNo

Open in new window


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
Alex [***Alex140181***]Software DeveloperCommented:
using DECODE:
decode(versionno, 0, null, lpad(to_char(versionno), 5, '0'))

Open in new window

using CASE:
case when versionno = 0 then null else lpad(to_char(versionno), 5, '0') end

Open in new window

NerdsOfTechTechnology ScientistCommented:
CASE and LPAD functions work for both databases. Assuming DocRevision is being tested as VersionNo:

	, d.DocumentNo
	, CASE d.DocRevision
	    ELSE ('\Ver' + LPAD(d.DocRevision, 5, '0')) 
	  END VersionNo
 FROM Project p
 LEFT JOIN Document d
 ON p.ProjectNo = d.ProjectNo 

Open in new window

So now the question is, if DocRevision is not being tested, where is VersionNo coming from? Is it a variable? More info is needed in this case.
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

From novice to tech pro — start learning today.