Solved

Using replacement in SQL 2005 Query

Posted on 2009-04-10
6
340 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
6 Comments
 
LVL 12

Expert Comment

by:udaya kumar laligondla
ID: 24116749
use
select 'C' as Col1,col2,...,colN form tableName where Col1=6
0
 
LVL 143

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
Efficient way to get backups off site to Azure

This user guide provides instructions on how to deploy and configure both a StoneFly Scale Out NAS Enterprise Cloud Drive virtual machine and Veeam Cloud Connect in the Microsoft Azure Cloud.

 
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

Online Training Solution

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action. Forget about retraining and skyrocket knowledge retention rates.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
sql query help 15 67
SQL Syntax 6 52
How do I partition this table on date? 5 54
Microsoft SQL Query sum values over time periods 3 25
by Mark Wills Attending one of Rob Farley's seminars the other day, I heard the phrase "The Accidental DBA" and fell in love with it. It got me thinking about the plight of the newcomer to SQL Server...  So if you are the accidental DBA, or, simp…
This article explains how to reset the password of the sa account on a Microsoft SQL Server.  The steps in this article work in SQL 2005, 2008, 2008 R2, 2012, 2014 and 2016.
Nobody understands Phishing better than an anti-spam company. That’s why we are providing Phishing Awareness Training to our customers. According to a report by Verizon, only 3% of targeted users report malicious emails to management. With compan…
This video shows how to use Hyena, from SystemTools Software, to update 100 user accounts from an external text file. View in 1080p for best video quality.

738 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