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 |
|
ben_53
Yak Posting Veteran
67 Posts |
Posted - 2011-08-24 : 17:38:16
|
| Hello,I have my_table with columns :col1 = IDCol2 = name (4 possible values)col3 = action (2 possible values)col4 = sequence (1,2...n)LOGIC:I want to create a stored procedure that can process the data according to the sequence from the column 'Sequence' col4.then I have 8 separate SPs ready.now this logic should look for sequence first then go to the corresponding SP.lets say for seq = 1 its should go for SP1seq 2 goes to SP4.. depending upon the col2 n col3 values. (8 possible matches)please write a SP and cursor script to run the above logic.Thanks. |
|
|
gwilson67
Starting Member
42 Posts |
Posted - 2011-08-25 : 00:23:55
|
| My suggestion would be to follow the steps below:1) Create the tsql with the cursor first to process the data accoring to the sequence from col42) One the sequence if found, put in the call to the stored proc3) Update the logic above based on col2 and col3 values4) Start with smaller pieces of TSQL and then merge it all togetherGreghttp://www.freewebstore.org/tsqlcoderepositoryPowerful tool for SQL Server development |
 |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2011-08-25 : 01:38:38
|
| why you need seperate sps for each of values of col4? why cant you integrate the logic into a single sp and parametrize it?------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/ |
 |
|
|
ben_53
Yak Posting Veteran
67 Posts |
Posted - 2011-08-25 : 13:30:24
|
| @gwilson67 : that would be my approach too but I need the code. I am not very good with cursors.@visakh: Those 8 SP's are very complex so want to handle them seperately. |
 |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2011-08-25 : 23:51:18
|
| but you can still put all logic inside one and parameterise it by means of if else construct------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/ |
 |
|
|
Transact Charlie
Master Smack Fu Yak Hacker
3451 Posts |
Posted - 2011-08-26 : 05:22:20
|
| I don't want you to take this the wrong way, there is no insult intended here:If you are as inexperienced in sql as you appear then it's very probable that the code inside those 'very complex' stored procs can be rewritten in a much denser, concise, more performant way. Also the resulting code would probably be easier to understand and be more beautiful.Visakah is trying to help by providing his (top quality) experience for free here. You are asking for something specific that *is not a good approach* and he's trying to help you pick a different approach rather than just giving you what you asked for.What's the harm of actually describing what you want rather than how you want to do it?Post the code of the stored procs if you want. You'll get suggestions and you'll learn a bunch.Charlie===============================================================Msg 3903, Level 16, State 1, Line 1736The ROLLBACK TRANSACTION request has no corresponding BEGIN TRANSACTION |
 |
|
|
|
|
|