Solved

Using replacement in SQL 2005 Query

Posted on 2009-04-10
6
332 Views
Last Modified: 2012-05-06
I have data like:
6,Test1,Test2,Test3
3,Test1,Test2,Test3
1,Test1,Test2,Test3
2,Test1,Test2,Test3

In a SQL 2005 Database (4 columns in my example).  I need to do a SQL * select query so that for records with a "6" in Col 1, it will replace the 6 with the letter "C" in the output.  Also, the query would only select records with a 6 in Col 1 (where Col1=6).  Is there an easy way to do replacements in SQL queries?

Thanks,

Joe
0
Comment
Question by:netwrked
6 Comments
 
LVL 12

Expert Comment

by:udayakumarlm
ID: 24116749
use
select 'C' as Col1,col2,...,colN form tableName where Col1=6
0
 
LVL 142

Accepted Solution

by:
Guy Hengel [angelIII / a3] earned 250 total points
ID: 24116750
you mean:
select 'C' col1, col2, col3, col4
 from yourtable
 where col1 = 6

Open in new window

0
 
LVL 5

Expert Comment

by:mfhorizon
ID: 24116760
select (case column1 when 6 then 'C' when 3 then 'd' when 1 'e' when 2 then 'f' end) column1, column2, column3, column4 from MYTABLE

enjoy!!1
0
What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

 
LVL 5

Assisted Solution

by:mfhorizon
mfhorizon earned 250 total points
ID: 24116780
In my example you can show uniqe alphabet on any given digit in your column 1. If you want this only for column value 6 and actual digit for other rows then use this query

select (case column1 when 6 then 'C' else column1 end) column1, column2, column3, column4 from MYTABLE

CHEERS!!

0
 
LVL 5

Expert Comment

by:mfhorizon
ID: 24116797
I appologize I forgoet 'then' in my first recommended query!!

just replace [  when 1 'e'   ] with [  when 1 then 'e'  ]

thanks
0
 

Author Closing Comment

by:netwrked
ID: 31568959
Both worked well, thanks!
0

Featured Post

Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

Join & Write a Comment

Introduction Hopefully the following mnemonic and, ultimately, the acronym it represents is common place to all those reading: Please Excuse My Dear Aunt Sally (PEMDAS). Briefly, though, PEMDAS is used to signify the order of operations (http://en.…
Use this article to create a batch file to backup a Microsoft SQL Server database to a Windows folder.  The folder can be on the local hard drive or on a network share.  This batch file will query the SQL server to get the current date & time and wi…
Here's a very brief overview of the methods PRTG Network Monitor (https://www.paessler.com/prtg) offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…
This video explains how to create simple products associated to Magento configurable product and offers fast way of their generation with Store Manager for Magento tool.

762 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

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now