Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2005 Forums
 Transact-SQL (2005)
 change values in SQL in already existing column

Author  Topic 

tamancha.1
Starting Member

37 Posts

Posted - 2010-05-03 : 16:03:17
How can we change values in SQL in already existing column if it satisfies certain condition.For Example:

Column A
1
2
3
4
46
55

Output
ColumnA
1
2
3
4
10+
10+

Replace any value greater than 10 with 10+. Can we use the case statement and maintain the same column name?

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2010-05-03 : 16:04:51
SELECT ColumnA = CASE WHEN ColumnA < 10 THEN ColumnA ELSE '10+' END
FROM ...

Depending upon the data type of ColumnA, you may need to convert it to varchar so that you can display "10+".

Tara Kizer
Microsoft MVP for Windows Server System - SQL Server
http://weblogs.sqlteam.com/tarad/

Subscribe to my blog
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2010-05-04 : 04:05:34
shouldnt it be ColumnA <= 10 ?

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2010-05-04 : 11:54:19
Maybe, but it wasn't clear from the sample data.

Tara Kizer
Microsoft MVP for Windows Server System - SQL Server
http://weblogs.sqlteam.com/tarad/

Subscribe to my blog
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2010-05-04 : 12:50:26
quote:
Originally posted by tkizer

Maybe, but it wasn't clear from the sample data.

Tara Kizer
Microsoft MVP for Windows Server System - SQL Server
http://weblogs.sqlteam.com/tarad/

Subscribe to my blog


the description said Replace any value greater than 10 with 10+

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2010-05-04 : 13:23:44
I certainly think the OP could have added <= if that's what he needed. I doubt he needed my post corrected.

In spoken/written English, we don't say greater than or equal to so it is up for interpretation. If it were my data, I would want 10 to show 10+ since that's what 10+ means.

Tara Kizer
Microsoft MVP for Windows Server System - SQL Server
http://weblogs.sqlteam.com/tarad/

Subscribe to my blog
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2010-05-04 : 13:28:36
Ok..May be you're right. Just told seeing the description.

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2010-05-04 : 13:52:04
Tamancha, let us know if you need further help.

Tara Kizer
Microsoft MVP for Windows Server System - SQL Server
http://weblogs.sqlteam.com/tarad/

Subscribe to my blog
Go to Top of Page
   

- Advertisement -