_ | 覦覈襦 | 豕蠏手 | 殊螳 | 譯殊碁
FrontPage › れ豢

Contents

1 ろ 一危 襷り鍵
2 NewID() 襯 伎 覦覯
3 TableSample 伎 覦覯
4 RAND() 伎蠍


1 ろ 一危 襷り鍵 #

CREATE TABLE users
(
uid int,
uname varchar(30)
)
GO

--Inserting 15 rows into the table users
SET NOCOUNT ON
INSERT [users] ([uid],[uname])VALUES(1,'Vyas Kondreddi')
INSERT [users] ([uid],[uname])VALUES(2,'Narayana Kondreddi')
INSERT [users] ([uid],[uname])VALUES(3,'Kondreddi')
INSERT [users] ([uid],[uname])VALUES(4,'Narayana Vyas Kondreddi')
INSERT [users] ([uid],[uname])VALUES(5,'Subhadra Jyothsna')
INSERT [users] ([uid],[uname])VALUES(6,'Geetha Madhuri Vungarala')
INSERT [users] ([uid],[uname])VALUES(7,'Sridhar Vungarala')
INSERT [users] ([uid],[uname])VALUES(8,'Vamsee Mohan')
INSERT [users] ([uid],[uname])VALUES(9,'Gopala Krishna Kondreddi')
INSERT [users] ([uid],[uname])VALUES(10,'Nagaja Devi Kondreddi')
INSERT [users] ([uid],[uname])VALUES(11,'Vijaya Madhuri Govindaraju')
INSERT [users] ([uid],[uname])VALUES(12,'Pamarthy Pradeep Kumar')
INSERT [users] ([uid],[uname])VALUES(13,'Pamarthy Harinath')
INSERT [users] ([uid],[uname])VALUES(14,'Vungarala Sathyanarayana')
INSERT [users] ([uid],[uname])VALUES(15,'Pamarthy Ramakrishna')
SET NOCOUNT OFF
GO

2 NewID() 襯 伎 覦覯 #

SELECT TOP 1
	uid
,	uname
FROM users
ORDER BY NewID()

一危一 襷朱 焔 .

3 TableSample 伎 覦覯 #

WHILE(1=1)
BEGIN
	SELECT TOP 1
		uid
	,	uname
	FROM users TABLESAMPLE(200 ROWS)
	
	IF @@ROWCOUNT > 0
		BREAK
END
一危郁 譬 襷 襦 襾轟 . 'TABLESAMPLE(n ROWS)' n 2 ~ 3 Page れ願 row覃 蟆企.

4 RAND() 伎蠍 #

--朱朱..
DECLARE @mx int, @mn int
SELECT @mx = MAX(uid), @mn = MIN(uid) FROM users
SELECT uid,uname [Lucky Winner is...] FROM users WHERE uid = ROUND(@mn + (RAND() * (@mx-@mn)),0)


--襷 譴螳 企宏 觜語 1螳 Row 覦讌 覈詩 企...

DECLARE @mx int, @mn int, @uid int, @uname varchar(200)
SELECT @mx = MAX(uid), @mn = MIN(uid) FROM users
WHILE(1=1)
BEGIN
	SELECT 
		@uid = uid
	,	@uname = uname 
	FROM users WHERE uid = ROUND(@mn + (RAND() * (@mx-@mn)),0)
	IF @@ROWCOUNT > 0 
		BREAK
END

SELECT @uid, @uname
覓企 一危郁 朱 願鍵 蟾讌 覦覯 伎螻, 一危郁 襷 企 Tablesample 伎 蟆 譬蟆.
蠍 蠍郁鍵..
企: : るジ讓曙 襦螻豺 企Ν 譯殊語. 襦螻豺
EditText : Print : Mobile : FindPage : DeletePage : LikePages : Powered by MoniWiki : Last modified 2018-04-13 23:12:53

語 讌 蟒覲企る 曙 谿 覺るΜ襯 蟆覲企る 襷 焔慨る 讌覲企ゼ 覿覲 磯豪慨る 豌 . ( 讌)