select name=(case TYPE when 'com' then [公司] when 'net' then [网点] when 'emp' then [职员] end)+name,[type] from tb
---------------------------------------------------------------- -- Author :fredrickhu(我是小F,向高手学习) -- Date :2010-01-27 12:00:07 -- Version: -- Microsoft SQL Server 2005 - 9.00.4035.00 (Intel X86) -- Nov 24 2008 13:01:59 -- Copyright (c) 1988-2005 Microsoft Corporation -- Developer Edition on Windows NT 5.2 (Build 3790: Service Pack 1) -- ---------------------------------------------------------------- --> 测试数据:[tb] if object_id('[tb]') is not null drop table [tb] go create table [tb]([NAME] varchar(4),[TYPE] varchar(3)) insert [tb] select '小王','com' union all select '小张','net' union all select '小李','emp' --------------开始查询-------------------------- select name=(case TYPE when 'com' then '[公司]' when 'net' then '[网点]' when 'emp' then '[职员]' end)+name,[type] from tb ----------------结果---------------------------- /* name type ---------- ---- [公司]小王 com [网点]小张 net [职员]小李 emp(3 行受影响) */
name=(case TYPE when 'com' then [公司] when 'net' then [网点] when 'emp' then [职员] end)+name,[type]
from
tb
-- Author :fredrickhu(我是小F,向高手学习)
-- Date :2010-01-27 12:00:07
-- Version:
-- Microsoft SQL Server 2005 - 9.00.4035.00 (Intel X86)
-- Nov 24 2008 13:01:59
-- Copyright (c) 1988-2005 Microsoft Corporation
-- Developer Edition on Windows NT 5.2 (Build 3790: Service Pack 1)
--
----------------------------------------------------------------
--> 测试数据:[tb]
if object_id('[tb]') is not null drop table [tb]
go
create table [tb]([NAME] varchar(4),[TYPE] varchar(3))
insert [tb]
select '小王','com' union all
select '小张','net' union all
select '小李','emp'
--------------开始查询--------------------------
select
name=(case TYPE when 'com' then '[公司]' when 'net' then '[网点]' when 'emp' then '[职员]' end)+name,[type]
from
tb
----------------结果----------------------------
/* name type
---------- ----
[公司]小王 com
[网点]小张 net
[职员]小李 emp(3 行受影响)
*/