Please start any new threads on our new
site at https://forums.sqlteam.com. We've got lots of great SQL Server
experts to answer whatever question you can come up with.
| Author |
Topic |
|
shubhada
Posting Yak Master
117 Posts |
Posted - 2007-03-12 : 05:06:56
|
| I have 2 tables as followCategory ahve lots of data for exPlanName category RNameContract Loss PQRContract Pay DEFContract General ABCContract Gereral TestContract General XYZdata Key SeqNbr TKey RName -------------- ---------- -------------- ------------------------------ 10128 1 62746 PQR10128 2 62747 DEF10128 3 62748 TEST10128 4 62749 XYZ10291 1 63839 PQR10291 2 63840 DEF10291 3 63841 ABC10291 4 63842 TESTI want to update the sequence of TEST after DEF as "ABC" and "TEST" is from same "Category" for Key 10291.For 10128 no need to change the squernce because this key have only "TEST" from category = "General"my O/p should beKey SeqNbr TKey RName -------------- ---------- -------------- ----------------------------10128 1 62746 PQR10128 2 62747 DEF10128 3 62748 TEST10128 4 62749 XYZ10291 1 63839 PQR10291 2 63840 DEF10291 3 63841 TEST10291 4 63842 ABC1.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 haveto be changed to 4, TKey to 63842 I want to create a proc for this. |
|
|
harsh_athalye
Master Smack Fu Yak Hacker
5581 Posts |
Posted - 2007-03-12 : 08:03:35
|
1.Select Key, count(RNAME) as [No of RNAMEs)from tbl t1 join category t2on t1.pk = t2.pkgroup by Keyhaving count(RNAME)>1 2. Why do you need procedure for this. Are you going to do this more than once. Also if seqnbr is key column, I suggest not to manipulate it for ordering purpose. Instead add some new column say, DisplayOrder, for this purpose.Harsh AthalyeIndia."The IMPOSSIBLE is often UNTRIED" |
 |
|
|
|
|
|