Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 267
  • Last Modified:

Replace

Hi all,

Please find the attachment,

I have a requirement where I need to replace the ISDN values into PRI from the Tag Column
I guess we have something like this select replace([tag_col],'ISDN','PRI') from tablename. this works fine.

I have another requirement where rest of the values in the tag_col should go null/blank.
It means I should have tag_col with 'PRI'  only.

please help out.
thanks in adv
test.xlsx
0
parpaa
Asked:
parpaa
  • 3
  • 3
  • 2
2 Solutions
 
RGBDartCommented:
just add

where replace([tag_col],'ISDN','PRI') = 'PRI'
0
 
RGBDartCommented:
[telepathy mode = on]
May be you want update items in that table, not select from it?
[telepathy mode = off]
If yes, query will be different
0
 
parpaaAuthor Commented:

@RGB many thanks for your sugg,
What if I want to update the table?? how the query will be?
0
Veeam Disaster Recovery in Microsoft Azure

Veeam PN for Microsoft Azure is a FREE solution designed to simplify and automate the setup of a DR site in Microsoft Azure using lightweight software-defined networking. It reduces the complexity of VPN deployments and is designed for businesses of ALL sizes.

 
Ephraim WangoyaCommented:


update table
set tag_col = 'PRI'
where tag_col = 'ISDN'
0
 
parpaaAuthor Commented:
UPDATE TABLE
SET TAG_COL ='PRI'
WHERE TAG_COL='ISDN'

what if I want rest of the records in the TAG_COL column be null ?
0
 
Ephraim WangoyaCommented:
Update table
Set tag_col =null
Where tag_col <> 'PRI' and tag_col <> 'ISDN'
0
 
RGBDartCommented:
first queries written by ewangoya and parpaa will replace values in tag_col column from ISDN to PRI. All the other row (not ISDN) will remain unchanged.

the last one will set tag_col  = null for all records that are not PRI and not ISDN
0
 
parpaaAuthor Commented:
Highly appreciated for your efforts and suggestions. Thank you so much.
0

Featured Post

What is SQL Server and how does it work?

The purpose of this paper is to provide you background on SQL Server. It’s your self-study guide for learning fundamentals. It includes both the history of SQL and its technical basics. Concepts and definitions will form the solid foundation of your future DBA expertise.

  • 3
  • 3
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now