Arjuna Aircraft Ident.: F-MBSD | Skylouck a écrit :
(heuresement puisque c SQL) par contre g ma preference pour Oracle car c celui que g utilisé le plus sinon SQL serveur bof Lot DTS et Proc Stockée bof, Ingres c celui que g le moins apprécié
|
Bah... Moi, là, maintenant, tout de suite, je viens de faire une requête à la con... Et euh... Comment dire...
Code :
- CREATE procedure icsd_ARTAssetList
- (
- @orgid int,
- @userid int,
- @date1 datetime,
- @date2 datetime,
- @invdate1 datetime,
- @invdate2 datetime,
- @leasescheduleid int = 0,
- @leasecontractid int = 0,
- @duration int = 0,
- @brand varchar(255) = '%',
- @lineOfProduct varchar(255) = '%',
- @manufacturerRef varchar(255) = '%',
- @description varchar(255) = '%',
- @category varchar(255) = '',
- @cat1 varchar(255) = '',
- @cat2 varchar(255) = '',
- @cat3 varchar(255) = '%',
- @serialnumber varchar(255) = '%',
- @supplier varchar(255) = '%',
- @invoice varchar(255) = '%',
- @ref1 varchar(255) = '%',
- @ref2 varchar(255) = '%',
- @ref3 varchar(255) = '%',
- @ref4 varchar(255) = '%',
- @ref5 varchar(255) = '%',
- @orderby varchar(255) = 'org'
- )
- AS
- BEGIN
- select orgid,
- name,
- leasescheduleid,
- schedule,
- -- inventory row
- -- inventory autoincrement
- manufacturerRef,
- SerialNumber,
- description,
- brand,
- lineOfProduct,
- category,
- cat1,
- cat2,
- cat3,
- supplier,
- numero,
- datecreation,
- reference1,
- reference2,
- reference3,
- reference4,
- reference5
- -- leasecontractid,
- -- contract,
- -- assetid
- from (
- select o.orgid,
- o.name,
- ls.leasescheduleid,
- ls.schedule,
- -- inventory row
- -- inventory autoincrement
- a.ProductCode manufacturerRef,
- a.SerialNumber,
- a.description,
- a.manufacture brand,
- a.brand lineOfProduct,
- zg.category,
- a.catalogType cat1,
- at1.value cat2,
- at2.value cat3,
- v.name supplier,
- zf.numero,
- zf.datecreation,
- a.reference1,
- a.reference2,
- a.reference3,
- a.reference4,
- a.reference5
- -- lc.leasecontractid,
- -- lc.contract,
- -- a.assetid
- from organization v, zfactures zf, zfactureasset zfa, sdViewAttributesValues at2, sdViewAttributesValues at1, zCatalogTypeGenre zg, asset a, zloyer zl, contractline cl, leasecontract lc, leaseschedule ls, zUserContractPerimeter zu, UserOrg uo, organization o
- where (o.orgid = @orgid or @orgid = 0)
- and o.type = 'C'
- and o.active = 'A'
- and uo.orgid = o.orgid
- and uo.userid = @userid
- and zu.userid = uo.userid
- and zu.orgid = uo.orgid
- and (zu.scheduleid = @leasescheduleid or @leasescheduleid = 0)
- and ls.orgid = o.orgid
- and ls.leasescheduleid = zu.scheduleid
- and ls.active = 'A'
- and ls.userights = 1
- and lc.orgid = ls.orgid
- and lc.leasescheduleid = ls.leasescheduleid
- and (lc.leasecontractid = @leasecontractid or @leasecontractid = 0)
- and (lc.leasecontractid = zu.contractid or zu.contractid = -1)
- and lc.active = 'A'
- and (lc.leasestopdate between @date1 and @date2 or @date1 > @date2)
- and (datediff(m, lc.leasestartdate, lc.leasestopdate) = @duration or @duration = 0)
- and cl.contractlineid = (select max(cl2.contractlineid)
- from contractline cl2
- where cl2.leasecontractid = lc.leasecontractid
- and cl2.active = 'A')
- and zl.leasecontractid = cl.leasecontractid
- and zl.contractlineid = cl.ContractLineID
- and a.orgid = o.orgid
- and a.linetype in ('B', 'S')
- and a.assetid = zl.assetid
- and a.manufacture like @brand
- and a.brand like @lineOfProduct
- and a.description like @description
- and a.catalogtype = @cat1
- and zg.catalogType = a.catalogType
- and zg.category = @category
- and at1.assetid = a.assetid
- and at1.attributename = zg.subcat1
- and at1.value = @cat2
- and at2.assetid = a.assetid
- and at2.attributename = zg.subcat2
- and at2.value like @cat3
- and zfa.assetid = a.assetid
- and zfa.leasescheduleid = ls.leasescheduleid
- and zfa.leasecontractid = lc.leasecontractid
- and zfa.contractlineid = cl.contractlineid
- and zf.factureid = zfa.factureid
- and zf.type = 'F'
- and a.serialNumber like @serialNumber
- and v.orgid = a.VendorOrgID
- and v.type = 'V'
- and zf.numero like @invoice
- and (zf.datecreation between @invdate1 and @invdate2 or @invdate1 > @invdate2)
- and a.reference1 like @ref1
- and a.reference2 like @ref2
- and a.reference3 like @ref3
- and a.reference4 like @ref4
- and a.reference5 like @ref5
- union
- select o.orgid,
- o.name,
- ls.leasescheduleid,
- ls.schedule,
- -- inventory row
- -- inventory autoincrement
- a.ProductCode manufacturerRef,
- a.SerialNumber,
- a.description,
- a.manufacture brand,
- a.brand lineOfProduct,
- zg.category,
- a.catalogType cat1,
- at1.value cat2,
- at2.value cat3,
- v.name supplier,
- zf.numero,
- zf.datecreation,
- a.reference1,
- a.reference2,
- a.reference3,
- a.reference4,
- a.reference5
- -- lc.leasecontractid,
- -- lc.contract,
- -- a.assetid
- from organization v, zfactures zf, zfactureasset zfa, sdViewAttributesValues at2, sdViewAttributesValues at1, zCatalogTypeGenre zg, asset a, zloyer zl, contractline cl, leasecontract lc, leaseschedule ls, UserOrg uo, organization o
- where (o.orgid = @orgid or @orgid = 0)
- and o.type = 'C'
- and o.active = 'A'
- and uo.orgid = o.orgid
- and uo.userid = @userid
- and ls.orgid = o.orgid
- and (ls.leasescheduleid = @leasescheduleid or @leasescheduleid = 0)
- and ls.active = 'A'
- and ls.userights = 0
- and lc.orgid = ls.orgid
- and lc.leasescheduleid = ls.leasescheduleid
- and lc.active = 'A'
- and (lc.leasecontractid = @leasecontractid or @leasecontractid = 0)
- and (lc.leasestopdate between @date1 and @date2 or @date1 is null or @date2 is null or @date1 > @date2)
- and (datediff(m, lc.leasestartdate, lc.leasestopdate) = @duration or @duration = 0)
- and cl.contractlineid = (select max(cl2.contractlineid)
- from contractline cl2
- where cl2.leasecontractid = lc.leasecontractid
- and cl2.active = 'A')
- and zl.leasecontractid = cl.leasecontractid
- and zl.contractlineid = cl.ContractLineID
- and a.orgid = o.orgid
- and a.linetype in ('B', 'S')
- and a.assetid = zl.assetid
- and a.manufacture like @brand
- and a.brand like @lineOfProduct
- and a.description like @description
- and a.catalogtype = @cat1
- and zg.catalogType = a.catalogType
- and zg.category = @category
- and at1.assetid = a.assetid
- and at1.attributename = zg.subcat1
- and at1.value = @cat2
- and at2.assetid = a.assetid
- and at2.attributename = zg.subcat2
- and at2.value like @cat3
- and zfa.assetid = a.assetid
- and zfa.leasescheduleid = ls.leasescheduleid
- and zfa.leasecontractid = lc.leasecontractid
- and zfa.contractlineid = cl.contractlineid
- and zf.factureid = zfa.factureid
- and zf.type = 'F'
- and a.serialNumber like @serialNumber
- and v.orgid = a.VendorOrgID
- and v.type = 'V'
- and zf.numero like @invoice
- and (zf.datecreation between @invdate1 and @invdate2 or @invdate1 > @invdate2)
- and a.reference1 like @ref1
- and a.reference2 like @ref2
- and a.reference3 like @ref3
- and a.reference4 like @ref4
- and a.reference5 like @ref5
- ) tmp
- order by case @orderby
- when 'org' then name
- when 'manufacturerRef' then manufacturerRef
- when 'SerialNumber' then SerialNumber
- when 'description' then description
- when 'brand' then brand
- when 'lineOfProduct' then lineOfProduct
- when 'category' then category
- when 'cat1' then cat1
- when 'cat2' then cat2
- when 'cat3' then cat3
- when 'supplier' then supplier
- when 'numero' then numero
- when 'datecreation' then datecreation
- when 'reference1' then reference1
- when 'reference2' then reference2
- when 'reference3' then reference3
- when 'reference4' then reference4
- when 'reference5' then reference5
- end, case @orderby
- when 'org' then schedule
- when 'manufacturerRef' then manufacturerRef
- when 'SerialNumber' then SerialNumber
- when 'description' then description
- when 'brand' then brand
- when 'lineOfProduct' then lineOfProduct
- when 'category' then category
- when 'cat1' then cat1
- when 'cat2' then cat2
- when 'cat3' then cat3
- when 'supplier' then supplier
- when 'numero' then numero
- when 'datecreation' then datecreation
- when 'reference1' then reference1
- when 'reference2' then reference2
- when 'reference3' then reference3
- when 'reference4' then reference4
- when 'reference5' then reference5
- end
- END
- GO
|
Ce patakesse, je dois le faire tourner sur 4 pages ASP différentes. Chaque fois avec des filtres différents et des clauses order by différentes...
Hé bien je suis très content de pouvoir la mettre en proc stock, et gérer ça proprement.
(sans parler du fait que la requête seule met euh... un peu plus d'une minute à tourner... une fois passée en PS, elle ne fait plus que 2 secondes, ce qui est quelque peu mieu) Message édité par Arjuna le 18-03-2005 à 17:34:49
|