CREATE PROCEDURE [dbo].[bdCustomerAllocate_sel]
@TranType varchar(40) = NULL,
@Id int = NULL,
@CustomerID int = NULL,
@OpenDate varchar(20) = NULL, //在 AS 之前的是形参,则程序中传值,程序中传值个数可少于形参个数,前提是没有被传的形参要赋值,如NULL
AS
DECLARE @CustoemrName varchar(20) //在As之后用 Declare定义变量,只在存储过程内部使用,不是形参。
SET @CustomerName = ''
IF(@TranType = 'personalcustomerlist')
BEGIN
SELECT a.id, b.CustomerName, b.Address, b.Tel,
(SELECT TOP 1 FollowDate FROM bdFollowRecord T(nolock)
WHERE T.AllocateID = a.ID) AS FollowDate
FROM bdCustomerAllocate a(NOLOCK)
JOIN bmdCustomer b(NOLOCK)
ON a.CustomerID = b.ID
WHERE a.IsValid = 1
END