| Author |
Topic |
|
rme8494
Yak Posting Veteran
98 Posts |
Posted - 2004-06-22 : 09:54:00
|
Hi All!Below is some code from a stored proc I'm writing. In this proc I have 3 steps...1. Add new customer data2. Get the MAC (ID) of the new customer for use outside of this SP3. Add any notes for this customer into a different table through another SP.My problem right now is with the 3rd step, executing the stored proc for the note information. When this proc is ran the MAC is null. I understand why it is null. I'm just wondering if there is some way to get the MAC selected in step 2 into the @MAC for step three without having to run another query. I can't do SELECT @MAC = MAC on step 2 because I need the step 2 query for use outside of this sp. Does that make sense?STEP 1 -- insert the new customer informationINSERT INTO TE_DCCustomer(Category_ID,CustomerName,PostBy)VALUES (@Category_ID,UPPER(@CustomerName),@SBCUID);STEP 2 -- get the MAC from the data you just enteredSELECT MACFROM TE_DCCustomerWHERE CustomerName = @CustomerName AND PostBy = @UID;STEP 3 IF @NoteInformation IS NOT NULLBEGIN-- add any note information for this customerEXEC usp_TE_DC_addNote @MAC,'N/A',@NoteInformation,@SBCUIDENDTHANKS!Ryan EverhartSBC |
|
|
Seventhnight
Master Smack Fu Yak Hacker
2878 Posts |
Posted - 2004-06-22 : 10:20:19
|
| how about:Step 2a:Select @Mac = mac From...Step 2b:Select Mac = @macStep 3:...Corey |
 |
|
|
Wanderer
Master Smack Fu Yak Hacker
1168 Posts |
Posted - 2004-06-22 : 10:21:27
|
from this, I am guessing that MAC is an identity integer column? Maybe you could post you table structure.If it is, you can use @@identity to give you that value. BOL example:INSERT INTO jobs (job_desc,min_lvl,max_lvl)VALUES ('Accountant',12,125)SELECT @@IDENTITY AS 'Identity'you might do a select @mac=@@identityHTH*##* *##* *##* *##* Chaos, Disorder and Panic ... my work is done here! |
 |
|
|
rme8494
Yak Posting Veteran
98 Posts |
Posted - 2004-06-22 : 10:23:15
|
| It is and Identity and I will try that out. all I need is this?SELECT @@IDENTITY AS 'Identity'Ryan EverhartSBC |
 |
|
|
rme8494
Yak Posting Veteran
98 Posts |
Posted - 2004-06-22 : 10:27:37
|
| That did work Wanderer, thanks!Ryan EverhartSBC |
 |
|
|
Wanderer
Master Smack Fu Yak Hacker
1168 Posts |
Posted - 2004-06-22 : 11:01:45
|
| No Prob :-)*##* *##* *##* *##* Chaos, Disorder and Panic ... my work is done here! |
 |
|
|
derrickleggett
Pointy Haired Yak DBA
4184 Posts |
Posted - 2004-06-22 : 11:57:51
|
| You should change @@IDENTITY to SCOPE_IDENTITY(). Just an fyi.MeanOldDBAderrickleggett@hotmail.comWhen life gives you a lemon, fire the DBA. |
 |
|
|
rme8494
Yak Posting Veteran
98 Posts |
Posted - 2004-06-22 : 12:00:57
|
| Derrick,This is what I have now...SET @mac = @@IDENTITY Should it beSET @mac = @@SCOPE_IDENTITY()ORSET @mac = SCOPE_IDENTITY()Thanks!Ryan Ryan EverhartSBC |
 |
|
|
derrickleggett
Pointy Haired Yak DBA
4184 Posts |
Posted - 2004-06-22 : 12:03:09
|
| SET @mac = SCOPE_IDENTITY()MeanOldDBAderrickleggett@hotmail.comWhen life gives you a lemon, fire the DBA. |
 |
|
|
|