最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

sql中參數(shù)過多利用變量替換參數(shù)的方法

 更新時(shí)間:2014年01月23日 15:22:20   作者:  
工作中遇到一個(gè)需求,需要非常多的參數(shù),本文為大家介紹下sql中利用變量替換參數(shù)過多的方法,需要的朋友不要錯(cuò)過
工作中遇到一個(gè)需求,需要非常多的參數(shù),例如如下sql,
復(fù)制代碼 代碼如下:

select
ff.fundsc||'-'||ff.fundtzfs||'-'||ff.fundcjfl||'-'||ff.fundonefl||'-'||ff.fundtowfl catagory,
sf.scode,replace(sf.fund5,'型證券投資基金','')fund5,sf.fund4,sf.fund10,
(select to_date(tradedate,'yyyy-MM-dd') from sdc_fundnetassetvalue where scode=sf.scode and tradedate in
(select max(tradedate) from sdc_fundnetassetvalue where scode=sf.scode and to_date(tradedate,'yyyyMMdd')>=(to_date(20120801,'yyyyMMdd')-10) and tradedate<=20120801) and rownum<2) trdatedate,
(select unitvalue from sdc_fundnetassetvalue where scode=sf.scode and tradedate in
(select max(tradedate) from sdc_fundnetassetvalue where scode=sf.scode and to_date(tradedate,'yyyyMMdd')>=(to_date(20120801,'yyyyMMdd')-10) and tradedate<=20120801) and rownum<2) fejz,
(select accumulatedunitvalue from sdc_fundnetassetvalue where scode=sf.scode and tradedate in
(select max(tradedate) from sdc_fundnetassetvalue where scode=sf.scode and to_date(tradedate,'yyyyMMdd')>=(to_date(20120801,'yyyyMMdd')-10) and tradedate<=20120801) and rownum<2) feljjz,
(select f30004_30002 from si_fund_30002 where f_fundcode=sf.scode and f_type=0 and f_tradingdate in
(select max(f_tradingdate) from si_fund_30002 where f_fundcode=sf.scode and to_date(f_tradingdate,'yyyyMMdd')>=(to_date(20120801,'yyyyMMdd')-10) and f_tradingdate<=20120801) and rownum<2) gqyzjzzzl,
(select f30006_30002 from si_fund_30002 where f_fundcode=sf.scode and f_type=0 and f_tradingdate in
(select max(f_tradingdate) from si_fund_30002 where f_fundcode=sf.scode and to_date(f_tradingdate,'yyyyMMdd')>=(to_date(20120801,'yyyyMMdd')-10) and f_tradingdate<=20120801) and rownum<2) gqyyjzzzl,
decode((select f30007_30002 from si_fund_30002 where f_fundcode=sf.scode and f_type=0 and f_tradingdate in
(select max(f_tradingdate) from si_fund_30002 where f_fundcode=sf.scode and to_date(f_tradingdate,'yyyyMMdd')>=(to_date(20120801,'yyyyMMdd')-10) and f_tradingdate<=20120801) and rownum<2),
null,'-',to_char((select f30007_30002 from si_fund_30002 where f_fundcode=sf.scode and f_type=0 and f_tradingdate in
(select max(f_tradingdate) from si_fund_30002 where f_fundcode=sf.scode and to_date(f_tradingdate,'yyyyMMdd')>=(to_date(20120801,'yyyyMMdd')-10) and f_tradingdate<=20120801) and rownum<2),'fm999999990.9999')) gqsgyjzzzl,
row_number() over(partition by ff.fundsc||'-'||ff.fundtzfs||'-'||ff.fundcjfl||'-'||ff.fundonefl||'-'||ff.fundtowfl
order by decode((select f30007_30002 from si_fund_30002 where f_fundcode=sf.scode and f_type=0 and f_tradingdate in
(select max(f_tradingdate) from si_fund_30002 where f_fundcode=sf.scode and to_date(f_tradingdate,'yyyyMMdd')>=(to_date(20120801,'yyyyMMdd')-10) and f_tradingdate<=20120801) and rownum<2),
null,'-',to_char((select f30007_30002 from si_fund_30002 where f_fundcode=sf.scode and f_type=0 and f_tradingdate in
(select max(f_tradingdate) from si_fund_30002 where f_fundcode=sf.scode and to_date(f_tradingdate,'yyyyMMdd')>=(to_date(20120801,'yyyyMMdd')-10) and f_tradingdate<=20120801) and rownum<2),'fm999999990.9999')) desc) sgy,
decode((select f30008_30002 from si_fund_30002 where f_fundcode=sf.scode and f_type=0 and f_tradingdate in
(select max(f_tradingdate) from si_fund_30002 where f_fundcode=sf.scode and to_date(f_tradingdate,'yyyyMMdd')>=(to_date(20120801,'yyyyMMdd')-10) and f_tradingdate<=20120801) and rownum<2),
null,'-',to_char((select f30008_30002 from si_fund_30002 where f_fundcode=sf.scode and f_type=0 and f_tradingdate in
(select max(f_tradingdate) from si_fund_30002 where f_fundcode=sf.scode and to_date(f_tradingdate,'yyyyMMdd')>=(to_date(20120801,'yyyyMMdd')-10) and f_tradingdate<=20120801) and rownum<2),'fm999999990.9999')) gqbnjzzzl,
row_number() over(partition by ff.fundsc||'-'||ff.fundtzfs||'-'||ff.fundcjfl||'-'||ff.fundonefl||'-'||ff.fundtowfl
order by decode((select f30008_30002 from si_fund_30002 where f_fundcode=sf.scode and f_type=0 and f_tradingdate in
(select max(f_tradingdate) from si_fund_30002 where f_fundcode=sf.scode and to_date(f_tradingdate,'yyyyMMdd')>=(to_date(20120801,'yyyyMMdd')-10) and f_tradingdate<=20120801) and rownum<2),
null,'-',to_char((select f30008_30002 from si_fund_30002 where f_fundcode=sf.scode and f_type=0 and f_tradingdate in
(select max(f_tradingdate) from si_fund_30002 where f_fundcode=sf.scode and to_date(f_tradingdate,'yyyyMMdd')>=(to_date(20120801,'yyyyMMdd')-10) and f_tradingdate<=20120801) and rownum<2),'fm999999990.9999')) desc) bn,
decode((select F30017_30003 from si_fund_30003 where f_fundcode=sf.scode and f_type=0 and f_tradingdate in
(select max(f_tradingdate) from si_fund_30003 where f_fundcode=sf.scode and to_date(f_tradingdate,'yyyyMMdd')>=(to_date(20120801,'yyyyMMdd')-10) and f_tradingdate<=20120801) and rownum<2),
null,'-',to_char((select F30017_30003 from si_fund_30003 where f_fundcode=sf.scode and f_type=0 and f_tradingdate in
(select max(f_tradingdate) from si_fund_30003 where f_fundcode=sf.scode and to_date(f_tradingdate,'yyyyMMdd')>=(to_date(20120801,'yyyyMMdd')-10) and f_tradingdate<=20120801) and rownum<2),'fm999999990.9999')) jinnian,
row_number() over(partition by ff.fundsc||'-'||ff.fundtzfs||'-'||ff.fundcjfl||'-'||ff.fundonefl||'-'||ff.fundtowfl
order by decode((select F30017_30003 from si_fund_30003 where f_fundcode=sf.scode and f_type=0 and f_tradingdate in
(select max(f_tradingdate) from si_fund_30003 where f_fundcode=sf.scode and to_date(f_tradingdate,'yyyyMMdd')>=(to_date(20120801,'yyyyMMdd')-10) and f_tradingdate<=20120801) and rownum<2),
null,'-',to_char((select F30017_30003 from si_fund_30003 where f_fundcode=sf.scode and f_type=0 and f_tradingdate in
(select max(f_tradingdate) from si_fund_30003 where f_fundcode=sf.scode and to_date(f_tradingdate,'yyyyMMdd')>=(to_date(20120801,'yyyyMMdd')-10) and f_tradingdate<=20120801) and rownum<2),'fm999999990.9999')) desc) jn,
decode((select f30009_30002 from si_fund_30002 where f_fundcode=sf.scode and f_type=0 and f_tradingdate in
(select max(f_tradingdate) from si_fund_30002 where f_fundcode=sf.scode and to_date(f_tradingdate,'yyyyMMdd')>=(to_date(20120801,'yyyyMMdd')-10) and f_tradingdate<=20120801) and rownum<2),
null,'-',to_char((select f30009_30002 from si_fund_30002 where f_fundcode=sf.scode and f_type=0 and f_tradingdate in
(select max(f_tradingdate) from si_fund_30002 where f_fundcode=sf.scode and to_date(f_tradingdate,'yyyyMMdd')>=(to_date(20120801,'yyyyMMdd')-10) and f_tradingdate<=20120801) and rownum<2),'fm999999990.9999')) gqynjzzzl,
row_number() over(partition by ff.fundsc||'-'||ff.fundtzfs||'-'||ff.fundcjfl||'-'||ff.fundonefl||'-'||ff.fundtowfl
order by decode((select f30009_30002 from si_fund_30002 where f_fundcode=sf.scode and f_type=0 and f_tradingdate in
(select max(f_tradingdate) from si_fund_30002 where f_fundcode=sf.scode and to_date(f_tradingdate,'yyyyMMdd')>=(to_date(20120801,'yyyyMMdd')-10) and f_tradingdate<=20120801) and rownum<2),
null,'-',to_char((select f30009_30002 from si_fund_30002 where f_fundcode=sf.scode and f_type=0 and f_tradingdate in
(select max(f_tradingdate) from si_fund_30002 where f_fundcode=sf.scode and to_date(f_tradingdate,'yyyyMMdd')>=(to_date(20120801,'yyyyMMdd')-10) and f_tradingdate<=20120801) and rownum<2),'fm999999990.9999')) desc) gqyn,
decode((select f30010_30002 from si_fund_30002 where f_fundcode=sf.scode and f_type=0 and f_tradingdate in
(select max(f_tradingdate) from si_fund_30002 where f_fundcode=sf.scode and to_date(f_tradingdate,'yyyyMMdd')>=(to_date(20120801,'yyyyMMdd')-10) and f_tradingdate<=20120801) and rownum<2),
null,'-',to_char((select f30010_30002 from si_fund_30002 where f_fundcode=sf.scode and f_type=0 and f_tradingdate in
(select max(f_tradingdate) from si_fund_30002 where f_fundcode=sf.scode and to_date(f_tradingdate,'yyyyMMdd')>=(to_date(20120801,'yyyyMMdd')-10) and f_tradingdate<=20120801) and rownum<2),'fm999999990.9999')) gqlnjzzzl,
row_number() over(partition by ff.fundsc||'-'||ff.fundtzfs||'-'||ff.fundcjfl||'-'||ff.fundonefl||'-'||ff.fundtowfl
order by decode((select f30010_30002 from si_fund_30002 where f_fundcode=sf.scode and f_type=0 and f_tradingdate in
(select max(f_tradingdate) from si_fund_30002 where f_fundcode=sf.scode and to_date(f_tradingdate,'yyyyMMdd')>=(to_date(20120801,'yyyyMMdd')-10) and f_tradingdate<=20120801) and rownum<2),
null,'-',to_char((select f30010_30002 from si_fund_30002 where f_fundcode=sf.scode and f_type=0 and f_tradingdate in
(select max(f_tradingdate) from si_fund_30002 where f_fundcode=sf.scode and to_date(f_tradingdate,'yyyyMMdd')>=(to_date(20120801,'yyyyMMdd')-10) and f_tradingdate<=20120801) and rownum<2),'fm999999990.9999')) desc) gqln,
decode((select f30011_30002 from si_fund_30002 where f_fundcode=sf.scode and f_type=0 and f_tradingdate in
(select max(f_tradingdate) from si_fund_30002 where f_fundcode=sf.scode and to_date(f_tradingdate,'yyyyMMdd')>=(to_date(20120801,'yyyyMMdd')-10) and f_tradingdate<=20120801) and rownum<2),
null,'-',to_char((select f30011_30002 from si_fund_30002 where f_fundcode=sf.scode and f_type=0 and f_tradingdate in
(select max(f_tradingdate) from si_fund_30002 where f_fundcode=sf.scode and to_date(f_tradingdate,'yyyyMMdd')>=(to_date(20120801,'yyyyMMdd')-10) and f_tradingdate<=20120801) and rownum<2),'fm999999990.9999')) gqsnjzzzl

from
(select
b.scode,b.fund5,b.fund4,b.fund10
from
sdc_fundbase b left join sdc_security a on b.scode=a.scode and b.mktcode=a.mktcode and b.fund49=a.stype
where
b.scode in (select t.fundcode from fund_fundcategoryone t where (t.fundtzfs='開放式' or t.fundtzfs='封閉式') and t.fundonefl!='貨幣市場(chǎng)基金' and t.fundonefl!='交易類' )
and (a.enddate>=to_date(20120801,'yyyy-MM-dd') or a.enddate is null or a.enddate=to_date(19000101,'yyyy-MM-dd'))
and a.stype in (6,7) order by scode
) sf
left join fund_fundcategoryone ff on sf.scode = ff.fundcode and ff.fundonefl!='交易類'

非常復(fù)雜,不仔細(xì)介紹,此時(shí)需要將20120801處全部變成參數(shù)傳入,,只寫參數(shù)就得累死我,下面方法可以節(jié)省我的好多工作量,在最內(nèi)部函數(shù)中修改select
b.scode,b.fund5,b.fund4,b.fund10,20120801 tdate
from
將20120801用tdate變量來代替,這樣傳入的參數(shù)就用tdate來表示就可以了。

相關(guān)文章

  • SQL SERVER 利用存儲(chǔ)過程查看角色和用戶信息的寫法

    SQL SERVER 利用存儲(chǔ)過程查看角色和用戶信息的寫法

    SQL SERVER 利用存儲(chǔ)過程查看角色(服務(wù)器/數(shù)據(jù)庫(kù))和用戶信息,感興趣的朋友可以了解下,或許對(duì)你有所幫助
    2013-01-01
  • win2003安裝sqlserver 2000提示無法驗(yàn)證產(chǎn)品密鑰的解決方法

    win2003安裝sqlserver 2000提示無法驗(yàn)證產(chǎn)品密鑰的解決方法

    由于腳本之家的安全設(shè)置,刪除了很多安全隱患的東西,也導(dǎo)致了一些軟件安裝出現(xiàn)錯(cuò)誤,所以建議大家在安裝好軟件再安全設(shè)置。今天就出現(xiàn)了安全sql2000時(shí)提示提示無法驗(yàn)證產(chǎn)品密鑰,下面的具體的解決方法。
    2011-07-07
  • SQL Server數(shù)據(jù)庫(kù)游標(biāo)的基本操作指南

    SQL Server數(shù)據(jù)庫(kù)游標(biāo)的基本操作指南

    這篇文章主要給大家介紹了關(guān)于SQL Server數(shù)據(jù)庫(kù)游標(biāo)的基本操作指南,SQL Server游標(biāo)是一種用于遍歷查詢結(jié)果集的數(shù)據(jù)庫(kù)對(duì)象,它可以逐行處理查詢結(jié)果,并執(zhí)行相關(guān)的操作,需要的朋友可以參考下
    2023-11-11
  • 模糊查詢

    模糊查詢

    模糊查詢...
    2006-08-08
  • SQL SERVER調(diào)用存儲(chǔ)過程小結(jié)

    SQL SERVER調(diào)用存儲(chǔ)過程小結(jié)

    在SQL Server數(shù)據(jù)庫(kù)的維護(hù)或者Web開發(fā)中,有時(shí)需要在存儲(chǔ)過程或者作業(yè)等其他數(shù)據(jù)庫(kù)操作中調(diào)用其它的存儲(chǔ)過程,下面介紹其調(diào)用的方法
    2015-11-11
  • SQL Server 版本變更檢查 警告

    SQL Server 版本變更檢查 警告

    SQL Server 版本變更檢查 警告,查看方法。
    2009-06-06
  • VS自帶的SQL server修改密碼并連接使用

    VS自帶的SQL server修改密碼并連接使用

    本文主要介紹了VS自帶的SQL server修改密碼并連接使用,文中通過示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧
    2023-04-04
  • SQL Server無日志恢復(fù)數(shù)據(jù)庫(kù)(2種方法)

    SQL Server無日志恢復(fù)數(shù)據(jù)庫(kù)(2種方法)

    SQL Server數(shù)據(jù)庫(kù)中的日志文件可能會(huì)由于一些突發(fā)事件或者失誤造成丟失的嚴(yán)重后果,大家都知道,SQL Server數(shù)據(jù)庫(kù)中日志文件是很重要的,所以要及時(shí)的將丟失的日志文件給找回來。下文就為大家介紹一種恢復(fù)數(shù)據(jù)庫(kù)日志文件的方法。
    2015-08-08
  • SQLserver2016鏡像備份不需要見證服務(wù)器(實(shí)戰(zhàn)親測(cè))

    SQLserver2016鏡像備份不需要見證服務(wù)器(實(shí)戰(zhàn)親測(cè))

    本文介紹了SQL2016鏡像備份的功能和優(yōu)勢(shì),包括數(shù)據(jù)保護(hù)、恢復(fù)和容災(zāi)等方面的應(yīng)用,具有一定的參考價(jià)值,感興趣的可以了解一下
    2023-10-10
  • SqlServer 復(fù)制中將大事務(wù)分成小事務(wù)分發(fā)的方法

    SqlServer 復(fù)制中將大事務(wù)分成小事務(wù)分發(fā)的方法

    日志讀取器代理可配置將大事務(wù)劃分為多個(gè)小事務(wù)進(jìn)行傳遞到分發(fā)數(shù)據(jù)庫(kù)中,分發(fā)隊(duì)列則按照小事務(wù)分發(fā)到訂閱數(shù)據(jù)庫(kù)中,這樣數(shù)據(jù)就很快同步
    2016-11-11

最新評(píng)論

旅游| 阿拉尔市| 沾益县| 白水县| 南涧| 桦川县| 四会市| 海伦市| 沛县| 陆丰市| 孟州市| 漯河市| 鄢陵县| 五原县| 拉萨市| 麟游县| 神农架林区| 教育| 措美县| 日土县| 资中县| 高青县| 嫩江县| 萨嘎县| 台安县| 阳春市| 杨浦区| 五常市| 沙坪坝区| 石渠县| 栾城县| 衡南县| 宽甸| 高清| 东明县| 丰台区| 新宁县| 巩留县| 横峰县| 乌恰县| 双城市|