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 |
|
G1ZmO
Starting Member
16 Posts |
Posted - 2010-10-28 : 07:10:25
|
What I'm trying to do within this storeproc is the following:Check the Job Number and Pallet ID (both varchars) in the Rackinglocs tableIf these both appear in the table then replace the Pallet ID with the actual location of the pallet from the Loc_ID field (varchar) from the Rackinglocs tableIf they dont appear in the above table then leave the Pallet ID aloneI then want to fill in a field on the stock table with either the actual location or failing that, the Pallet_ID-- Pull the stock location from the RackingLocs_tbldeclare @Loc_ID varchar(15)Select Job_No, Pallet_ID, Loc_ID from RackingLocs_tbl -- EK0739, PLT01, E30where Job_No = @Job_No -- If Stock location exists in RackingLocs_tbl then use itIF @Loc_ID = @Stock_Loc -- ie if both equal PLT01 then -- ****************The procedure works up till this point*********************BEGIN select @Loc_ID = Loc_ID from RackingLocs_tbl --replace contents of parameter with physical location E30ENDELSE -- Otherwise use Pallet_ID as Stock_tbl.Stock_Loc select @Loc_ID = @Stock_Loc Currently it's just storing the original pallet ID (e.g. PLT01) into the stock table even though I know that the rackinglocs table has the physical location present (E30)Thanks--PaulComplete SQL newbie! |
|
|
RickD
Slow But Sure Yak Herding Master
3608 Posts |
Posted - 2010-10-28 : 07:32:48
|
Where are you setting @Loc_ID?Did you mean to set it in the SELECT?Select Job_No, Pallet_ID, @Loc_ID = Loc_ID from RackingLocs_tbl -- EK0739, PLT01, E30where Job_No = @Job_No |
 |
|
|
G1ZmO
Starting Member
16 Posts |
Posted - 2010-10-28 : 08:03:31
|
No, it already exists in the RackingLocs_tbl as Job_No:EK0739, Pallet_ID:PLT01, Loc_ID:E30I should clarify that the RackingLocs_tbl is only temporary as a leftover from the previous db and will be removed after each line in the stock table has it's location updatedOh sorry, I see what you mean but it should only be set the same as Loc_ID if the job_no and Pallet ID exist in that table--PaulComplete SQL newbie! |
 |
|
|
G1ZmO
Starting Member
16 Posts |
Posted - 2010-10-28 : 08:37:23
|
Ah! I got it! Your hint helped :)-- Pull the stock location from the RackingLocs_tbldeclare @Loc_ID varchar(15)declare @Pallet_ID varchar(15)Select @Loc_ID = Loc_ID ,@Pallet_ID = Pallet_ID from RackingLocs_tblwhere Job_No = @Job_No IF @Stock_Loc = @Pallet_IDBEGIN select @Loc_ID = Loc_ID from RackingLocs_tblENDELSE select @Loc_ID = @Stock_Loc --PaulComplete SQL newbie! |
 |
|
|
RickD
Slow But Sure Yak Herding Master
3608 Posts |
Posted - 2010-10-28 : 09:05:03
|
Glad you got it sorted. |
 |
|
|
|
|
|
|
|