Please start any new threads on our new site at http://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

Our new SQL Server Forums are live! Come on over! We've restricted the ability to create new threads on these forums.

SQL Server Forums
Profile | Active Topics | Members | Search | Forum FAQ
Username:
Password:
Save Password
Forgot your Password?

 All Forums
 Other Forums
 SQL Server 6.5 \ SQL Server 7.0
 How to create select statement and Split Data
 Reply to Topic
 Printer Friendly
Author  Topic Next Topic  

kjubnoi
Starting Member

Thailand
3 Posts

Posted - 06/26/2013 :  01:23:39  Show Profile  Reply with Quote
I have output data xx rows from 1 Statement. I want to Split output Data from 1 Statement to 20%, 30%, 50% of xx rows

i have data :
pd_id values
1001 115
1002 65
1003 55
1008 43
1010 33
1011 21
1013 20
1025 12
1033 11
1035 10

i want to show rank and seq follow below :
pd_id values rank seq
1001 115 A 1
1002 65 A 2
1003 55 B 1
1008 43 B 2
1010 33 B 3
1011 21 C 1
1013 20 C 2
1025 12 C 3
1033 11 C 4
1035 10 C 5

pls, help me

khtan
In (Som, Ni, Yak)

Singapore
17689 Posts

Posted - 06/26/2013 :  01:52:32  Show Profile  Reply with Quote
Are you really using SQL Server 6.5 / 7 ? It is much easier if you are using SQL 2005 or later


KH
Time is always against us

Go to Top of Page

kjubnoi
Starting Member

Thailand
3 Posts

Posted - 06/26/2013 :  03:19:58  Show Profile  Reply with Quote
thank for read my forums, I use sql server 7 because this place use only sql server 7
Go to Top of Page

khtan
In (Som, Ni, Yak)

Singapore
17689 Posts

Posted - 06/26/2013 :  04:13:03  Show Profile  Reply with Quote
create a temp table with column rank char(1), output the result of your existing query to a temp table


-- update the rank in temp table
update	t
set	rank	= case 	when 	rn * 100.0 / (select count(*) from #temp) <= 20
			then	'A'
			when	rn * 100.0 / (select count(*) from #temp) <= 50 -- 20 + 30 = 50
			then	'B'
			else	'C'
			end
from
(
	select	*, rn = (select count(*) from #temp x where x.pd_id <= t.pd_id)
	from	#temp t
) t		

-- the final query
select	*,
	seq	= (select count(*) from #temp x where x.rank = t.rank and x.pd_id <= t.pd_id)
from	#temp t



KH
Time is always against us

Go to Top of Page

kjubnoi
Starting Member

Thailand
3 Posts

Posted - 06/27/2013 :  03:03:01  Show Profile  Reply with Quote
thank very much, khtan ^^ and i have a question ... Can we create select statement by use only 1 statement ??? (not use temp table or update)
Go to Top of Page

khtan
In (Som, Ni, Yak)

Singapore
17689 Posts

Posted - 06/27/2013 :  20:48:01  Show Profile  Reply with Quote
don't think it is possible with SQL Server 7


KH
Time is always against us

Go to Top of Page

rhein
Starting Member

9 Posts

Posted - 12/17/2017 :  02:58:29  Show Profile  Reply with Quote
<strong><a href="http://www.timberlandonlinestop.top/sv/">timberland rabatterade skor</a></strong><br><strong><a href="http://www.timberlandonlinestop.top/sv/">rabatt timberland stövlar</a></strong><br>[b][url=http://www.timberlandonlinestop.top/sv/]timberland skor[/url][/b] | [b]<a href="http://www.timberlandonlinestop.top/sv/">timberland utlopp</a>[/b] | [b][url=http://www.timberlandonlinestop.top/sv/]timberland skor[/url][/b]timberland män t6562r skrivbordet stövlar. [Timberlandoutlet059] - SEK 1,367 : Timberland , timberlandonlinestop.top US Dollar Euro GB Pound Canadian Dollar Australian Dollar Jappen Yen Norske Krone Swedish Krone Danish Krone CNYKategorier[url=http://www.timberlandonlinestop.top/sv/m%C3%A4n-timberland-boat-st%C3%B6vlar-c-1.html]Män Timberland Boat stövlar [/url][url=http://www.timberlandonlinestop.top/sv/timberland-classic-10061-c-2.html]Timberland Classic 10061 [/url][url=http://www.timberlandonlinestop.top/sv/kvinnor-timberland-6-tum-c-4.html]kvinnor timberland 6 tum. [/url][url=http://www.timberlandonlinestop.top/sv/kvinnor-timberland-roll-top-st%C3%B6vlar-c-5.html]Kvinnor Timberland Roll Top stövlar [/url][url=http://www.timberlandonlinestop.top/sv/m%C3%A4n-timberland-6-inch-st%C3%B6vlar-c-3.html]Män Timberland 6 Inch stövlar [/url]<a class="category-top" href="http://www.timberlandonlinestop.top/sv/m%C3%A4n-timberland-roll-top-st%C3%B6vlar-c-6.html"><span class="category-subs-selected">Män Timberland Roll Top stövlar </span></a>Utvalda - [url=http://www.timberlandonlinestop.top/sv/featured_products.html] [mer][/url] [url=http://www.timberlandonlinestop.top/sv/]Hem[/url] :: [url=http://www.timberlandonlinestop.top/sv/m%C3%A4n-timberland-roll-top-st%C3%B6vlar-c-6.html]Män Timberland Roll Top stövlar [/url] :: timberland män t6562r skrivbordet stövlar. .jqzoom{float:left;position:relative;padding:0px;cursor:pointer;width:301px;height:300px;} [url=http://www.timberlandonlinestop.top/sv/timberland-m%C3%A4n-t6562r-skrivbordet-st%C3%B6vlar-p-60.html]timberland män t6562r skrivbordet stövlar. [/url]timberland män t6562r skrivbordet stövlar. SEK 2,817 SEK 1,367Spara: 51% mindreVänligen välj: Choose Size US10=UK9.5=EUR44 US11=UK10.5=EUR45 US7.5=UK7=EUR41 US7=UK6.5=EUR40 US8.5=UK8=EUR42 US9=UK8.5=EUR43 Lägg i korgen: [url=http://www.timberlandonlinestop.top/sv/timberland-m%C3%A4n-t6562r-skrivbordet-st%C3%B6vlar-p-60.html]/timberland119/Men-Timberland-Roll/Timberland-Men-Roll-Top-Boots-Yellow-T6562R.jpg[/url] timberland män t6562r skrivbordet stövlar. [url=http://www.timberlandonlinestop.top/sv/images//timberland119/Men-Timberland-Roll/Timberland-Men-Roll-Top-Boots-Yellow-T6562R.jpg]/timberland119/Men-Timberland-Roll/Timberland-Men-Roll-Top-Boots-Yellow-T6562R.jpg[/url][url=http://www.timberlandonlinestop.top/sv/images//timberland119/Men-Timberland-Roll/Timberland-Men-Roll-Top-Boots-Yellow-T6562R-1.jpg]/timberland119/Men-Timberland-Roll/Timberland-Men-Roll-Top-Boots-Yellow-T6562R-1.jpg[/url][url=http://www.timberlandonlinestop.top/sv/images//timberland119/Men-Timberland-Roll/Timberland-Men-Roll-Top-Boots-Yellow-T6562R-2.jpg]/timberland119/Men-Timberland-Roll/Timberland-Men-Roll-Top-Boots-Yellow-T6562R-2.jpg[/url] Artikelnr: Timberlandoutlet059 Related Products[url=http://www.timberlandonlinestop.top/sv/timberland-m%C3%A4n-skrivbordet-st%C3%B6vlar-svart-t20064-p-58.html]timberland män skrivbordet stövlar svart t20064[/url][url=http://www.timberlandonlinestop.top/sv/timberland-m%C3%A4n-skrivbordet-st%C3%B6vlar-svart-t20064-p-58.html]timberland män skrivbordet stövlar svart t20064 [/url][url=http://www.timberlandonlinestop.top/sv/timberland-m%C3%A4n-skrivbordet-st%C3%B6vlar-brown-t44514-p-22.html]timberland män skrivbordet stövlar brown t44514[/url][url=http://www.timberlandonlinestop.top/sv/timberland-m%C3%A4n-skrivbordet-st%C3%B6vlar-brown-t44514-p-22.html]timberland män skrivbordet stövlar brown t44514 [/url][url=http://www.timberlandonlinestop.top/sv/timberland-m%C3%A4n-skrivbordet-st%C3%B6vlar-ljusgul-t36517-p-33.html]timberland män skrivbordet stövlar ljusgul t36517[/url]<a href="http://www.timberlandonlinestop.top/sv/timberland-m%C3%A4n-skrivbordet-st%C3%B6vlar-ljusgul-t36517-p-33.html">timberland män skrivbordet stövlar ljusgul t36517 </a><a href="http://www.timberlandonlinestop.top/sv/timberland-m%C3%A4n-t44516-skrivbordet-st%C3%B6vlar-p-85.html"><img src="http://www.timberlandonlinestop.top/sv/images/_small//timberland119/Men-Timberland-Roll/Timberland-Men-Roll-Top-Boots-yellow-T44516.jpg" alt="timberland män t44516 skrivbordet stövlar." title=" timberland män t44516 skrivbordet stövlar. " width="160" height="105" /></a>[url=http://www.timberlandonlinestop.top/sv/timberland-m%C3%A4n-t44516-skrivbordet-st%C3%B6vlar-p-85.html]timberland män t44516 skrivbordet stövlar. [/url] [url=http://www.timberlandonlinestop.top/sv/index.php?main_page=product_reviews_write&products_id=60&number_of_uploads=0]Skriv en recension[/url] [url=http://www.timberlandonlinestop.top/sv/index.php]Hem[/url] [url=http://www.timberlandonlinestop.top/sv/index.php?main_page=shippinginfo]frakt[/url] [url=http://www.timberlandonlinestop.top/sv/index.php?main_page=Payment_Methods]grossist[/url] [url=http://www.timberlandonlinestop.top/sv/index.php?main_page=shippinginfo]beställa spårning[/url] [url=http://www.timberlandonlinestop.top/sv/index.php?main_page=Coupons]kuponger[/url] [url=http://www.timberlandonlinestop.top/sv/index.php?main_page=Payment_Methods]betalningsmetoder[/url] [url=http://www.timberlandonlinestop.top/sv/index.php?main_page=contact_us]kontakta oss[/url] <a href="http://www.timberlandonlinestop.top/sv/timberland-m%C3%A4n-t6562r-skrivbordet-st%C3%B6vlar-p-60.html" ><IMG src="http://www.timberlandonlinestop.top/sv/includes/templates/polo/images/payment.png" width="672" height="58"></a>Copyright © 2012 alla rättigheter förbehållna. [b][url=http://www.timberlandonlinestop.top/sv/]timberland rabatterade skor[/url][/b][b][url=http://www.timberlandonlinestop.top/sv/]rabatt timberland stövlar[/url][/b]<a href="http://CheapRolexWatches17.webs.com"> stövlar. blog </a>[url=http://monclercoats663.webs.com] stövlar [/url][url=http://SwissClassicReplicaBreitling2.webs.com] About timberlandonlinestop.top blog [/url]
Go to Top of Page
   Topic Next 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