General discussion

Locked

Stored Procedure Help.

By ty_masterson ·
Hello. here is a stored procedure I have made. Basically, I have two drop down lists on a form. One contains account numbers and the other contains territories to transfer that account to. One of the items in the Territories DDL is called Inside Sales, which is broken down into a number of different departments. So what I want to happen is when the user selects this particular item, Inside Sales, the procedure looks up the state the account selected is located in, and insert the proper IS number (i.e. is1, is2, is3, etc.) that is associated with that state. Here is how I have started off, but I am confused as to how i would go about writing this if statement IF 'Inside Sales' is selected.


CREATE PROCEDURE [UpdateToTerritory]
 
@AccountID Char(10),
@ToName nvarchar(50)

AS UPDATE accounttransferstestmike

 
Set ToTerritoryID = territories.TerritoryID, ToRegionID = Regions.RegionID, ToDivisionID = Divisions.DivisionID, ToEmpID = Employees.EmployeeID
FROM accounts2, Accounts, ISD, EndoscopySqlUser.Territories INNER JOIN 
EndoscopySqlUser.Regions ON EndoscopySqlUser.Territories.RegionName = EndoscopySqlUser.Regions.Region INNER JOIN 
EndoscopySqlUser.Employees ON EndoscopySqlUser.Territories.TerritoryID = EndoscopySqlUser.Employees.TerritoryID INNER JOIN 
EndoscopySqlUser.Divisions ON EndoscopySqlUser.Regions.Division = EndoscopySqlUser.Divisions.DivisionID 
 
WHERE @AccountID = Accounts.AccountID AND @ToName = territories.TerritoryName AND ToTerritoryID is NULL AND territories.CloseDate is NULL

[red]if @ToName = 'Inside Sales' then
select Territories.TerritoryName like 'IS'
Where (Accounts.State = ISD.State)[/red]

GO

This conversation is currently closed to new comments.

0 total posts (Page 1 of 1)  
| Thread display: Collapse - | Expand +

All Comments

Back to Software Forum
0 total posts (Page 1 of 1)  

Related Discussions

Related Forums