SQL Server Management Studio,存儲過程如何檢查存儲過程中的值爲空?
我從Visual Studio傳遞customerName
,並在存儲過程中我想獲取customerID
。
現在我想檢查一下customerId
是否爲空,表示這是一個新客戶。如果是這樣,我想在表格中插入該客戶。然後我想獲取客戶ID,並且想要存儲在TableB
中。
下面是示例代碼:
還告訴如何執行
if(@customerId == null)
{
Insert customerDetails into CustomerTable;
get CustomerId.
} //General workflow what i want.
爲此,我寫了一個SQL Server存儲過程
create procedure Customers_AddData2
@CustomerName nvarchar(50) = null
As
--Get Customer ID
declare @CustomerID numeric(18, 0)= (SELECT distinct [CustomerID] FROM [tblCustomerMaster] WHERE CustomerName = @CustomerName)
--checking if customerId not found
-- Here is some error, Not getting syntax
IF(@CustomerID IS NULL == true)
{
INSERT INTO [tblCustomerMaster] ([CustomerName])
VALUES (CustomerName)
}
-- Now get customer id
@CustomerID numeric(18, 0)= (SELECT distinct [CustomerID] FROM [tblCustomerMaster] WHERE CustomerName = @CustomerName)
如果(ISNULL(@CustomerID)== 1)的http:// forums.mysql.com/read.php?98,198593 – BaBL86