根據業務需要,在水晶報表中把資料庫的多條記錄顯示為集成為一條。即把同一id號的出件接收時間集成為一條,且標識出是第幾條的接收時間。
資料庫中的資料樣式如下:
said receiveddate
000104 2006-03-01
000104 2006-03-04
000104 2006-03-07
000104 2006-03-08
000105 2006-08-09
-----------水晶報表中顯示的樣式為:
said 1st received date 2nd received date 3rd received date 4th received date
000104 2006-03-01 2006-03-04 2006-03-07 2006-03-08
000105 2006-08-09
---------------------sql語句為:
code
select[sa
].[said],
max(
case
when
xh =
1then
sentdate
end)
asemailnotice
,max
(case
when
xh =
2then
sentdate
end)
asfirstreminder
,max
(case
when
xh =
3then
sentdate
end)
assecondreminder
,max
(case
when
xh =
4then[sa
].[lastreminderdate
]end
) as
alerttoqcs ,[
sa].[
vendorname],
[sa].
[factoryname
]from
(select
*,xh=(
select
xh =
count(*
) from[#a
]where
a.referenceid
=referenceid
anda.xid
>=
xid)
from[#a
]a) b , [sa
]where[sa
].[said]=
b.referenceid
and(
isnull
(@customerid,''
)=''or[sa
].customerid
=@customerid
) and
(isnull
(@vendorid,''
)=''or[sa
].vendorid
=@vendorid
) and
(isnull
(@factoryid,''
)=''or[sa
].factoryid
=@factoryid
) and
(isnull
(@begindate,'
1999-1-1')
='1999-1-1'or
[sa].firstreminderdate
>=
@begindate
) and
(isnull
(@enddate,'
2999-1-1')
='2999-1-1'or
[sa].firstreminderdate
<=
@enddate
) and
(isnull
(@said1,''
)=''or
cast([
sa].said
asint
) >=
cast
(@said1
asint
)) and
(isnull
(@said2,''
)=''or
cast
(sa.said
asint
)<=
cast
(@said2
asint
)) and[sa
].confirmed=1
and[sa]
.booked=0
andsa.deleted=0
andsa.companyid
=@companyid
andsa.departmentid
=@departmentid
andsa.
[divisionid]=
@divisionid
group
byreferenceid,[sa
].[vendorname],
[sa].
[factoryname],
[sa].
[said
]drop
table
#a
SqlServer 插入多條資料
插入一條資料使用default關鍵字 insert into student studentno,loginpwd,studentname,gradeid,phone,address,borndate,email values 001 12345 張三 男 1,1234567890123 defau...
sql server 分庫合併
參考 sqlserver 伺服器架構遷移 2,sql server 中心訂閱模型 多發布單訂閱 思路 是 分庫建立發布,然後新伺服器訂閱所有分庫進行資料彙總 需要注意 分庫建立發布的時候 1,分庫的發布還是需要做sid 的篩選 2,選擇設定所有表,設定屬性 名稱已被使用時的操作 為 刪除資料,如果目...
Oracle 將多條update語句合併為一條
1.oracle版本 11g 2.mybatis版本 3.2.3 批量修改資料,但where條件不一樣。表名 tablename 要求將字段a的值為1的資料修改其欄位b的值為 b1 將字段a的值為2的資料修改其欄位b的值為 b2 將字段a的值為3的資料修改其欄位b的值為 b3 一 對此可以寫3條up...