日期:2014-05-18 浏览次数:20541 次
create view a_and_b as select * from a union select * from b go
------解决方案--------------------
CREATE table #A (ID INT,NAME VARCHAR(10),[TIME] SMALLDATETIME)
insert #A
select 1 ,'zhao', '05/06/2011' UNION ALL
SELECT 2 ,'zhao' ,'05/07/2011'
CREATE table #B (ID INT,NAME VARCHAR(10),[TIME] SMALLDATETIME)
insert #B
select 1,'zhao1', '05/05/2011' UNION ALL
SELECT 2,'zhao1', '05/07/2011'
DECLARE @CDATE SMALLDATETIME
SET @CDATE='05/05/2011'
IF EXISTS (SELECT * FROM #A WHERE [TIME]=@CDATE)
(SELECT * FROM #A WHERE [TIME]=@CDATE)
ELSE
(SELECT * FROM #B WHERE [TIME]=@CDATE )
ID NAME TIME
----------- ---------- -----------------------
1 zhao1 2011-05-05 00:00:00
(1 行受影响)
------解决方案--------------------
SELECT * FROM A WHERE TIME = '05/05/2011' IF @@ROWCOUNT = 0 SELECT * FROM B WHERE TIEM = '05/05/2011'