SQL Server Forums
Profile | Register | Active Topics | Members | Search | Forum FAQ
 
Register Now and get your question answered!
Username:
Password:
Save Password
Forgot your Password?

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 how to select random numbers from a large table
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

vandana
Starting Member

29 Posts

Posted - 03/28/2013 :  00:42:46  Show Profile  Reply with Quote
Hi,

How to select random numbers(1,3,5,7,9......)
from a large table without using top,and without cte

can anyone suggest me the soultion

bandi
Flowing Fount of Yak Knowledge

India
2223 Posts

Posted - 03/28/2013 :  00:55:42  Show Profile  Reply with Quote

SELECT * FROM employees
  WHERE (ABS(CAST(
  (BINARY_CHECKSUM(*) *
  RAND()) as int)) % 100) < 10
Go to Top of Page

vandana
Starting Member

29 Posts

Posted - 03/28/2013 :  00:59:50  Show Profile  Reply with Quote
am getting only 2 rows
and that to 3 ,4
but i want the rows 1,3,5,7,9.....
Go to Top of Page

bandi
Flowing Fount of Yak Knowledge

India
2223 Posts

Posted - 03/28/2013 :  01:03:31  Show Profile  Reply with Quote
do you need odd number fo rows?
Go to Top of Page

vandana
Starting Member

29 Posts

Posted - 03/28/2013 :  01:06:53  Show Profile  Reply with Quote
yes
Go to Top of Page

vandana
Starting Member

29 Posts

Posted - 03/28/2013 :  01:16:20  Show Profile  Reply with Quote
Hey i got it

thanks
Go to Top of Page

bandi
Flowing Fount of Yak Knowledge

India
2223 Posts

Posted - 03/28/2013 :  01:20:02  Show Profile  Reply with Quote
there are multiple ways... post your solution... It will help others who has that kind of problem
Go to Top of Page

vandana
Starting Member

29 Posts

Posted - 03/28/2013 :  01:24:25  Show Profile  Reply with Quote
1. SELECT * FROM(
SELECT ROW_NUMBER()OVER (ORDER BY empno)AS ROW,* FROM emp)
A WHERE ROW%2=1


2. Select * from emp where (empno% 2) = 1
Go to Top of Page
  Previous Topic Topic Next Topic  
 New Topic  Reply to Topic
 Printer Friendly
Jump To:
SQL Server Forums © 2000-2009 SQLTeam Publishing, LLC Go To Top Of Page
This page was generated in 0.05 seconds. Powered By: Snitz Forums 2000