General discussion
June 16, 2004 at 12:30 PM
ty_masterson

Stored Procedure Help.

by ty_masterson . Updated 22 years, 3 months ago

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.

[code]
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

[/code]

This discussion is locked

All Comments