搜尋功能,並動態顯示使用者選擇的貨位,可以通過下面的儲存過程去實現。aspx頁面,即放乙個gridview即可。
本例程,可以學會如何使用臨時表,迴圈表,和字串連線,動態sql語句與執行。
貨位集合
@compareoperator
nvarchar
(100
) --條件)
asbegin
--建立臨時表,放存貨位,以便做迴圈記錄動作
ifobject_id('
#tempcargospace')
isnot
null
drop
table
#tempcargospace
create
table
#tempcargospace
(
id int
identity(1
,1),cargospaceid
smallint
,cargospacename
nvarchar(50
))
end--
宣告變數
--下面有兩個變數,宣告之後,馬上賦值為'',如果不這樣實現,那在下面字串連線時,null與任何字串連線之後,還是null
declare
@nint
,@rows
int,
@cargospacefield
nvarchar
(100) =
'',@cargospacefield1
nvarchar
(100) =
'',@comparecondition
nvarchar
(500
)set@n=
1--如果使用者有選擇貨位if(
len(
@cargospacecollection
) >
0)
--從貨位表中搜尋出貨位主健,名稱存入臨進表中。
execute('
insert into #tempcargospace([cargospaceid],[cargospacename]) select [cargospaceid],[cargospacename] from [dbo].[cargospace] where [cargospaceid] in ('+
@cargospacecollection+'
)')else
--如果沒有選擇貨位的話,把貨位表中所有記錄插入臨時表中
insert
into
#tempcargospace(
[cargospaceid],
[cargospacename])
select
[cargospaceid],
[cargospacename
]from
[dbo].
[cargospace]--
記錄發生的記錄筆數
set@rows
=@@rowcount
--開始迴圈臨時表
while
@n<=
@rows
begin
declare
@cargospaceid
nvarchar(30
),@cargospacename
nvarchar(50
)
--找出每筆記錄的貨位主鍵與貨位名稱
select
@cargospaceid=[
cargospaceid],
@cargospacename=[
cargospacename
]from
#tempcargospace
where[id
]=@n--
在aspx網頁中將會顯示這些組合成字段,如:,[1] as [預設貨位],[2] as [cr1],[3] as [src]....
set@cargospacefield
=@cargospacefield+'
,['+@cargospaceid+'
] as ['+
@cargospacename+'
]'--下面句,組成條件所需欄位,如:,[1],[2],[3]....
set@cargospacefield1
=@cargospacefield1+'
,['+@cargospaceid+'
]'set@n=@n
+1end--
臨時表迴圈結束if(
len(
@cargospacefield
) >0)
--截除前面的「,」
set@cargospacefield
=substring
(@cargospacefield,2
,len
(@cargospacefield
)) if(
len(
@cargospacefield1
) >
0)
--截除前面的「,」
set@cargospacefield1
=substring
(@cargospacefield1,2
,len
(@cargospacefield1
))--
如果使用者有選擇條件話,條件如:<> 10if(
len(
@compareoperator
) >
0)
--每個字段套用條件,結果如:[1] <> 10 or [2] <> 10 or [3] <> 10
set@comparecondition
=replace
(replace
(@cargospacefield1,'
,','
or '),'
]','
]'+@compareoperator
) begin
declare
@sql
nvarchar
(4000
) ='
select [itemcode] as [物料編碼],[itemgeneralname] as [物料說明],[unitmeasurename] as [單位],'+
@cargospacefield+'
from [dbo].[udf_itemgeneralstock]()'if
(len
(@compareoperator) =
0)
select
@sql
=@sql+'
order by [itemcode]
'elseif(
len(
@compareoperator
) >0)
select
@sql
=@sql+'
where '+
@comparecondition+'
order by [itemcode]
'execute
sp_executesql
@sql
end
動態顯示 XML布局
題目有點抽象,下面給大家簡單說下這種情況出現的實際情況,我講後,你就會明白這法子太有用了。在實際用途中,特別是咱們做網路處理的的時候,有時候介面是根據返回的資料來做的,那麼layout 定義的那些固定布局肯定就滿足不了我們的需求了。這個時候就會出現這種情況 linearlayou linear ne...
C 動態顯示窗體
windows提供了乙個api函式animate window,該函式可以實現窗體的動畫效果,animatewindow函式在c 中的宣告如下。dllimportattribute user32.dll private static extern bool animatewindow intptr ...
MPAndroidChart 動態顯示藍芽資料
在一次用matlab對前端串列埠資料處理時,某臉上露出一絲不易覺察的笑意,突發奇想地要把串列埠資料在手機上顯示出來。好在網上有成熟的例子,我的實現過程是建立在以下基礎上 1 藍芽通訊採用 手機藍芽串列埠的除錯助手demo實現 提供的方法,簡單明瞭,上機即行。2 資料顯示採用乙個優秀的第三方庫 mpa...