_ | 覦覈襦 | 豕蠏手 | 殊螳 | 譯殊碁
FrontPage › 蠏螳讌覲旧″危襴貅伎燕

Contents

1 覓語
2


1 覓語 #

れ螻 螳 企 .
num         a1          a2          a3          a4          
----------- ----------- ----------- ----------- ----------- 
1           1           2           3           4
2           5           6           7           8
3           9           10          11          12


蟆曙一 磯 轟 貉殊 伎襷 觜手 襦 碁襦 蟆郁骸襯 覦伎 . 襯 る a2 貉殊 る れ螻 螳 蟆郁骸襯 覦伎 .
a1          
----------- 
1
3 --2 觜讌
4
5
7
8 --6 觜讌
9
11 --10 觜讌
12

2 #

譴觜
USE TEMPDB
GO
--DROP TABLE TEST2
CREATE TABLE TEST2(NUM INT PRIMARY KEY,A1 INT, A2 INT, A3 INT, A4 INT)
INSERT INTO TEST2 VALUES(1,1,2,3,4)
INSERT INTO TEST2 VALUES(2,5,6,7,8)
INSERT INTO TEST2 VALUES(3,9,10,11,12)
SELECT * FROM TEST2
GO

願屋
--ろ螻: 覈 CLUSTERED INDEX SEEK 讌襷 觜 襷 れ願. 
--WHERE 觜朱 企ろ磯 碁煙 れ 讌襷 觜 譴企 蟆 覲  .
SELECT A1 FROM TEST2
WHERE NUM > 0
UNION
SELECT A2 FROM TEST2
WHERE NUM > 0
UNION
SELECT A3 FROM TEST2
WHERE NUM > 0
UNION
SELECT A4 FROM TEST2
WHERE NUM > 0
 
--一危一 覿  磯殊 ろ螻 れ  る  .
--WHERE企 GROUP BY襯 伎伎 蟆  一危磯 ″ 蟆 譬.
--襷 る狩伎 FIRST_ROW覦 牛磯伎襯  碁る...
--OPTION(FAST 10) 朱  碁.
 
SELECT A1 FROM TEST2
--WHERE NUM = 1 --企蟆 磯覃 UNION ALL  觜 る.
UNION
SELECT A2 FROM TEST2
--WHERE NUM = 1
UNION
SELECT A3 FROM TEST2
--WHERE NUM = 1
UNION
SELECT A4 FROM TEST2
--WHERE NUM = 1
OPTION(FAST 12)
 
 
-- 蟆 伎伎  襦襯 襷.
CREATE PROC PROC_TEST  @A1 BIT = 1, @A2 BIT = 1, @A3 BIT = 1, @A4 BIT = 1
AS
BEGIN
DECLARE @SQL VARCHAR(200)
SET @SQL = ''
 
IF(@A1=1)
             SET @SQL = 'SELECT A1 FROM TEST2 UNION '
IF(@A2=1) 
             SET @SQL = @SQL + 'SELECT A2 FROM TEST2 UNION '
IF(@A3=1)
             SET @SQL = @SQL + 'SELECT A3 FROM TEST2 UNION '
IF(@A4=1)
             SET @SQL = @SQL + 'SELECT A4 FROM TEST2'
EXEC(@SQL)
END
GO
 
SELECT * FROM TEST2
EXEC PROC_TEST 1,0,1,1 -- 貉殊 1,   貉殊 0 襷り覲襦 
 
--譬  襴覃 れ螻 螳   .
CREATE PROC PROC_TEST2  @A1 BIT = 1, @A2 BIT = 1, @A3 BIT = 1, @A4 BIT = 1
AS
BEGIN
   SELECT A1 FROM TEST2
   WHERE 1 = @A1
   UNION
   SELECT A2 FROM TEST2
   WHERE 1 = @A2
   UNION
   SELECT A3 FROM TEST2
   WHERE 1 = @A3
   UNION
   SELECT A4 FROM TEST2  
   WHERE 1 = @A4
END
GO
SELECT * FROM TEST2
EXEC PROC_TEST2 1,0,1,1

れ襦 企 觜蠏 覓語 襷 危語 殊企. 讌企 MSSQL Server 企 伎 企 覲伎 . 螳襦襯 碁襦 シ豺蠍 伎 螳 UNION企 UNION ALL 伎 . 螳襦襦 襷 シ豎 る 蠏碁 觜 . れ襦 螳 煙碁 螳 貉殊朱 覿襴螳 朱襦 碁煙るゼ 覈 燕 碁企.
蠍 蠍郁鍵..
企: : るジ讓曙 襦螻豺 企Ν 譯殊語. 襦螻豺
EditText : Print : Mobile : FindPage : DeletePage : LikePages : Powered by MoniWiki : Last modified 2018-04-13 23:12:53

螳 蠍一 螳襯伎殊 螳 蟆 螳襯伎 .