?
Solved

Using replacement in SQL 2005 Query

Posted on 2009-04-10
6
Medium Priority
?
343 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 1000 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
Back Up Your Microsoft Windows Server®

Back up all your Microsoft Windows Server – on-premises, in remote locations, in private and hybrid clouds. Your entire Windows Server will be backed up in one easy step with patented, block-level disk imaging. We achieve RTOs (recovery time objectives) as low as 15 seconds.

 
LVL 5

Assisted Solution

by:mfhorizon
mfhorizon earned 1000 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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

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…
'Between' is such a common word we rarely think about it but in SQL it has a very specific definition we should be aware of. While most database vendors will have their own unique phrases to describe it (see references at end) the concept in common …
In this brief tutorial Pawel from AdRem Software explains how you can quickly find out which services are running on your network, or what are the IP addresses of servers responsible for each service. Software used is freeware NetCrunch Tools (https…
Want to learn how to record your desktop screen without having to use an outside camera. Click on this video and learn how to use the cool google extension called "Screencastify"! Step 1: Open a new google tab Step 2: Go to the left hand upper corn…

719 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