這是我通過檢查給定的名稱來選擇詳細信息的代碼。
在這裏我想通過開始字母來做名稱過濾......我該怎麼做呢?帶起始字母的過濾器名稱
select * from tblcustomer
where
customername=case @customername
when null then customername
else @customername
這是我通過檢查給定的名稱來選擇詳細信息的代碼。
在這裏我想通過開始字母來做名稱過濾......我該怎麼做呢?帶起始字母的過濾器名稱
select * from tblcustomer
where
customername=case @customername
when null then customername
else @customername
它不是C#,它是SQL。 在SQL中可以使用like
子句。 例如:select * from tblcustomer where CustomerName like 'A%'
它會顯示客戶的名字開始與信A
編輯
DECLARE @CustomerName varchar(200) = NULL
SELECT TOP 100 * FROM tblCustomer
WHERE CustomerName like CASE WHEN @CustomerName IS NULL THEN '%' ELSE @CustomerName + '%' END
即SQL,不C#。 –