Tycoon Talk
Become a Big fish!
The number 1 forum for online business!
Post topics, ask questions, share your knowledge.
Tycoon Talk is part of Freelancer.com - find skilled workers online at a fraction of the cost.

The Database Forum


You are currently viewing our The Database Forum as a guest. Please register to participate.
Login



Reply
Old 03-13-2007, 10:56 PM Query Help
Novice Talker

Posts: 4
Trades: 0
I have 2 tables as follow

Category ahve lots of data for ex

PlanName category RName
Contract Loss PQR
Contract Pay DEF
Contract General ABC
Contract Gereral Test
Contract General XYZ


data

Key SeqNbr TKey RName
-------------- ---------- -------------- ------------------------------
10128 1 62746 PQR
10128 2 62747 DEF
10128 3 62748 TEST
10128 4 62749 XYZ
10291 1 63839 PQR
10291 2 63840 DEF
10291 3 63841 ABC
10291 4 63842 TEST

I want to resqeuence the Rname those are coming from "General" category.

For Ex - update the sequence of TEST.It should be after DEF
As "TEST" and ABC is from same "Category" for Key 10291.
For 10128 no need to change the squernce because this key have only "TEST" from category = "General"

I want the O/p as follow

Key SeqNbr TKey RName
-------------- ---------- -------------- ----------------------------
10128 1 62746 PQR
10128 2 62747 DEF
10128 3 62748 TEST
10128 4 62749 XYZ
10291 1 63839 PQR
10291 2 63840 DEF
10291 3 63841 TEST
10291 4 63842 ABC

1.PLz tell me how I can find out key which have more than 1 RName from "General" Category and also

2.plz tell me how I can update

TEST SeqNbr would need to be changed to 3,
TKey to 63841 .ABC SeqNbr would have
to be changed to 4, TKey to 63842

I want to create a proc for this.
shubhada99 is offline
Reply With Quote
View Public Profile
 
 
Register now for full access!
Old 03-13-2007, 11:28 PM Re: Query Help
ForrestCroce's Avatar
Half Man, Half Amazing

Posts: 3,023
Name: Forrest Croce
Location: Seattle, WA
Trades: 0
What database are you using? If it's SQL Server 2005 things will be much easier than with other dbs.

You can find out how many keys have the same value using a subquery. You would do something like Select *, (Select Count(*) From x Where key = table.key) From table.

I don't understand how you're trying to resequence your data? You're describing the logic you would use to change the order of your results, but everything is an exception to a set of rules I don't know about. If you can explain this more clearly, you'll probably get better results. ( Or, maybe I'm just missing something, and someone else will come along with better advice. )
__________________

Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
ForrestCroce is offline
Reply With Quote
View Public Profile Visit ForrestCroce's homepage!
 
Old 03-14-2007, 12:02 AM Re: Query Help
Novice Talker

Posts: 4
Trades: 0
I am using SQL server 2000.
I want to change the sequence because of the business requirment.
How i can maintain the privious data?
and what about the update?
shubhada99 is offline
Reply With Quote
View Public Profile
 
Old 03-14-2007, 05:17 PM Re: Query Help
Learning Newbie's Avatar
Defies a Status

Latest Blog Post:
Astounding Republican Paranoia
Posts: 5,662
Name: John Alexander
Trades: 0
What is the business requirement that forces you to change the sequence? Because right now, the only advice we can give you is to write your query like this:

SELECT * FROM Table ORDER BY RANDOM()
Learning Newbie is offline
Reply With Quote
View Public Profile
 
Reply     « Reply to Query Help
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off





   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML



Page generated in 0.13318 seconds with 12 queries