日期:2014-05-16 浏览次数:20565 次
----------------------------------------------------------------
-- Author :DBA_HuangZJ(发粪涂墙)
-- Date :2014-03-11 14:57:18
-- Version:
-- Microsoft SQL Server 2008 R2 (RTM) - 10.50.1600.1 (X64)
-- Apr 2 2010 15:48:46
-- Copyright (c) Microsoft Corporation
-- Enterprise Edition (64-bit) on Windows NT 6.2 <X64> (Build 9200: ) (Hypervisor)
--
----------------------------------------------------------------
--> 测试数据[A]
if object_id('[A]') is not null drop table [A]
go
create table [A]([a] nvarchar(2),[b] nvarchar(2),[c] nvarchar(2),[d] nvarchar(4),[e] nvarchar(2))
insert [A]
select 'X','X','X','02','X' union all
select 'X','X','X','SA','X' union all
select 'X','X','X','SA','X' union all
select 'X','X','X','02','X' union all
select 'X','X','X','02','X' union all
select 'X','X','X','FX','X'
--> 测试数据[B]
if object_id('[B]') is not null drop table [B]
go
create table [B]([a] nvarchar(2),[b] nvarchar(4),[c] nvarchar(6))
insert [B]
select 'X','02','AAA' union all
select 'X','SA','BBB' union all
select 'X','FX','CCC'
--------------生成数据--------------------------
SELECT a.a,a.b,a.c,b.c,a.d
FROM a INNER JOIN b ON a.d=b.b
/*
a b c c d
---- ---- ---- ------ ----
X X X AAA 02
X X X BBB SA
X X X BBB SA
X X X AAA 02
X X X AAA 02
X X X CCC FX
*/