zimmer9
asked on
Building a Stored Procedure based on parameters and variables
If you were building a Stored Procedure and working on the FROM clause, how would you code it to handle a situation where the FROM clause part of the SQL statement that you are building could have 1 of 2 outcomes ?
Let's assume a parameter named @DomFor is passed to the Stored Proc and if it has a value of 1, then the first statement that follows is used to build the FROM clause. If @DomFor has a value of 2, then the second statement is used to build the FROM clause.
1)
FROM tblStatesAll AS S INNER JOIN (tblCustomers AS C INNER JOIN tblProducts AS P ON C.CustomerNumber = P.CustomerNumber) ON
S.StateFS = C.State
2)
FROM tblStatesAll AS S INNER JOIN (tblCustomers AS C INNER JOIN tblProducts AS P ON C.CustomerNumber = P.CustomerNumber) ON
S.StateFS <> C.State
Let's assume a parameter named @DomFor is passed to the Stored Proc and if it has a value of 1, then the first statement that follows is used to build the FROM clause. If @DomFor has a value of 2, then the second statement is used to build the FROM clause.
1)
FROM tblStatesAll AS S INNER JOIN (tblCustomers AS C INNER JOIN tblProducts AS P ON C.CustomerNumber = P.CustomerNumber) ON
S.StateFS = C.State
2)
FROM tblStatesAll AS S INNER JOIN (tblCustomers AS C INNER JOIN tblProducts AS P ON C.CustomerNumber = P.CustomerNumber) ON
S.StateFS <> C.State
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.