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
 General SQL Server Forums
 New to SQL Server Programming
 case

Author  Topic 

pascal_jimi
Posting Yak Master

167 Posts

Posted - 2013-06-24 : 01:42:43
declare @table3 table(phone2 int) --
insert into @table3 values(111111)
insert into @table3 values(222222)
insert into @table3 values(333333)
insert into @table3 values(444444)
insert into @table3 values(555555)
insert into @table3 values (666666)
SELECT
CASE WHEN Phone2 between 111111 and 333333 then 'A'

END as Phone2
from @table3


result query

------

Phone2

A
A
A
null
null
null




----

how can I get a resulting table so

Phone2

A
A
A
444444
555555
666666



kmkmmm

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2013-06-24 : 01:44:06
you need a else to handle other values

SELECT
CASE WHEN Phone2 between 111111 and 333333 then 'A' else CAST(Phone2 AS varchar(10))

END as Phone2
from @table3


------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/
https://www.facebook.com/VmBlogs
Go to Top of Page

pascal_jimi
Posting Yak Master

167 Posts

Posted - 2013-06-24 : 01:47:36
Request completed with error

kmkmmm
Go to Top of Page

pascal_jimi
Posting Yak Master

167 Posts

Posted - 2013-06-24 : 01:48:36
sorry

thak you for help


kmkmmm
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2013-06-24 : 01:48:51
welcome

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/
https://www.facebook.com/VmBlogs
Go to Top of Page
   

- Advertisement -