需要您對複選框的幫助。 這裏是我的代碼:帶有複選框的SQL SERVER示例
CREATE PROCEDURE stad_list
@inp_location_code numeric (3,0) = -1
@inp_item_code_bgn numeric (5,0) = -1
@inp_item_code_end numeric (5,0) = -1
@inp_shipped numeric (2,0) = 0, --checkbox, if it is checked then returns the items in table which were shipped (value in table is 1)
@inp_check numeric (2,0) = 0, --checkbox, if it is checked then returns data which is still in process of checking for availability in warehouse (value in table is 0)
@inp_not_ship numeric(2,0) = 0 --checkbox, if it is checked then returns data which had not been shipped during some problems (valuein table is 2)
AS
BEGIN
SET NOCOUNT ON;
DECLARE @SELECT as varchar (3000) = ''
DECLARE @WHERE as varchar (1000) = ''
IF (@inp_location_code != -1)
SET @WHERE = @WHERE + ' WHERE [dbo].item.location =' + CONVERT(varchar,@inp_location_code)
IF (@inp_item_code_bgn != -1)
SET @WHERE = @WHERE + ' AND [dbo].item.code>=' + CONVERT(varchar, @inp_item_code_bgn)
IF (@inp_item_code_end != -1)
SET @WHERE = @WHERE + ' AND [dbo].item.code<=' + CONVERT(varchar, @inp_item_code_end)
IF (@inp_shipped = 1)
SET @WHERE = @WHERE + ' AND [dbo].item.ship = 1'
IF (@inp_check = 1)
SET @WHERE = @WHERE + ' AND [dbo].item.ship = 0'
IF (@inp_not_ship = 1)
SET @WHERE = @WHERE + ' AND [dbo].item.ship = 2'
SET @SELECT = @SELECT + '
SELECT
[dbo].item.name as ''NAME'',
[dbo].item.location as ''LOCATION'',
[dbo].item.code as ''CODE'',
[dbo].item.ship as ''STATUS''
FROM [dbo].item '
+ @WHERE
EXEC (@SELECT)
RETURN @@ROWCOUNT
END
它,當我只檢查一個複選框工作正常,但不能得到任何數據,同時它的2進行檢查。那麼,如果我想檢查兩個複選框,該怎麼辦?有什麼建議麼?
這裏是我的表
Id Item_code Item_name Item_location Item_ship
1 14789 Juice Tokyo 0
2 14785 Boots Tokyo 2
3 98744 Hat Osaka 0
4 36987 Socks Kyoto 1
而且有三個複選框
發貨
檢查
不發貨
如果我託運發貨後輸出會是這樣:
Id Item_code Item_name Item_location Item_ship
4 36987 Socks Kyoto 1
,但我想爲前這樣做。當我檢查發貨和檢查,然後輸出將是:
Id Item_code Item_name Item_location Item_ship
1 14789 Juice Tokyo 0
3 98744 Hat Osaka 0
4 36987 Socks Kyoto 1
沒有足夠的信息。需要樣本輸入數據和預期輸出。 – 2013-03-27 10:50:53
用複選框部分的OR替換AND。不要忘記ORed條件下的括號。 – Arvo 2013-03-27 10:56:40
我已經編輯了我的問題與例子,如你問...對不起,如果它太長 – user2082503 2013-03-27 11:01:51