1. 運輸確認--運輸證選擇 (not in 自連線,內連線)
select distinct
t0.u_transportarno as '運輸證編號' ,
t0.u_fromdate as '有效期從' ,
t0.u_todate as '有效期到' ,
t0.u_itemcode as '物料**' ,
t0.u_itemname as '物料名稱',
t0.u_quantity as '可用數量' ,
t0.u_counts as '有效次數'
from [@transportar] t0
where t0.u_itemcode=(
select t1.u_itemcode
from [@transfer_lines1] t1
where t1.lineid=$[@transfer_lines2.u_transferline]
and t1.docentry=$[@transfer.docentry])
and $[@transfer_lines2.u_deliverdate]>=t0.u_fromdate
and $[@transfer_lines2.u_deliverdate]<=t0.u_todate
and t0.u_transportarno
not in(
select t0.u_transportarno as '運輸證編號'
from [@transportar] t0
where
t0.u_counts=(select count(*) from [@transfer_lines2] where u_linestatus='c' ))
for browse
2. --sql變數的賦值
declare @now datetime;
select @now=getdate();
print @now;
declare @ordernum int;
select @ordernum = count(1) from [@transfer];--這條查詢語句只是用來 對 變數進行賦值的,不會返回查詢結果的.
print @ordernum;
SQL 中樹形結構查詢的運用
use tempdb go 建立演示環境 create table dept id int primary key,parent id int,name nvarchar 20 insert dept select 0,0,n 全部 union all select 1,0,n 財務部 union ...
oracle中sql的遞迴查詢運用
當表自查詢的時候,就基本會用到遞迴的查詢 比如乙個員工表 主鍵 名字 職位 上級id 部門id id name zhiwei sid y100 1000 張三 經理 0 y100 1001 李四 組長 1000 y100 1002 王五 員工 1001 y100 1003 趙六 員工 1001 y1...
hql 中的case when運用查詢
有以下hql string hql select new com.ks.admin.report.dto.reportmonthwithdrawaldto count sum ct.tradetotal sum case when ct.tradetotal 0 then 1 else 0 end ...