日期:2014-05-17  浏览次数:20451 次

请问这种合并怎么写。
字段1 字段2 字段3
a
b
c


从SQL 查询出来如上,想把它合并到如下:

字段4
a
b
c


请问怎么合并呢?

------解决方案--------------------
----------------------------
-- Author  :DBA_Huangzj
-- Date    :2013-01-08 16:23:26
-- Version:
--      Microsoft SQL Server 2008 R2 (SP1) - 10.50.2500.0 (X64) 
-- Jun 17 2011 00:54:03 
-- Copyright (c) Microsoft Corporation
-- Enterprise Edition (64-bit) on Windows NT 6.1 <X64> (Build 7601: Service Pack 1, v.721)
--
----------------------------
--> 测试数据:[huang]
if object_id('[huang]') is not null drop table [huang]
go 
create table [huang]([字段1] varchar(1),[字段2] varchar(1),[字段3] varchar(1))
insert [huang]
select 'a',null,null union all
select null,'b',null union all
select null,NULL,'c'
--------------开始查询--------------------------

select COALESCE([字段1],[字段2],[字段3])
from [huang]
----------------结果----------------------------
/* 
----
a
b
c

(3 行受影响)
*/