Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium


SQL - create a string with bracket if not null

Posted on 2012-09-16
Medium Priority
Last Modified: 2012-09-16
I like to create a string with bracket if not null, but return a blank string '' if null.

e.g. if the string is 'ABC',  I will like to get (ABC)
if the string is null, I will like to get an empty string ''

How will I do that?
Question by:tommym121
LVL 25

Accepted Solution

lwadwell earned 2000 total points
ID: 38403760
use ISNULL to turn the null value into an empty string, concatenate the str with the brackets to get the bracketed string ... if the value the was null, concatenation will be null still.  e.g.
    select isnull('('+str+')',''), str
    from (select 'abc' as str union all select null)v

Author Closing Comment

ID: 38404181

Featured Post

[Webinar] Database Backup and Recovery

Does your company store data on premises, off site, in the cloud, or a combination of these? If you answered “yes”, you need a data backup recovery plan that fits each and every platform. Watch now as as Percona teaches us how to build agile data backup recovery plan.

Question has a verified solution.

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

Naughty Me. While I was changing the database name from DB1 to DB_PROD1 (yep it's not real database name ^v^), I changed the database name and notified my application fellows that I did it. They turn on the application, and everything is working. A …
SQL Server engine let you use a Windows account or a SQL Server account to connect to a SQL Server instance. This can be configured immediatly during the SQL Server installation or after in the Server Authentication section in the Server properties …
Screencast - Getting to Know the Pipeline
Is your OST file inaccessible, Need to transfer OST file from one computer to another? Want to convert OST file to PST? If the answer to any of the above question is yes, then look no further. With the help of Stellar OST to PST Converter, you can e…

571 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