Bonjour,
J'ai un problème d'écriture de requête.
J'ai une table MTARIF avec
MTAR_ID int ID PK autoincrement
MARC_ID int (id de la marchandise pour ce tarif)
MTAR_DATEDEBUT smalldatetime (date de début de validité du tarif)
MTAR_DATEFIN smalldatetime (date de finde validité du tarif)
MTAR_MONTANT decimal(18,2) valeur du tarif
les tarifs changent et peuvent être saisis à l'avance.
Je souhaiterais connaître pour une date donnée le tarif en cours et le
tarif
précédent. EN sachant qu'il peur y avoir plusieurs tarifs précédents et
que
je souhaite le dernier plus proche de la date saisie.
J'ai écrit cette procédure
CREATE PROCEDURE dbo.tarif_liste
@date smalldatetime
a.mtar_id as MTAR_ID
,t.marc_id as marc_id
,convert(varchar(20),t.mtar_datedebut,103) as debut
,t.mtar_montant as nouveauMontant
,a.mtar_montant as ancienMontant
from TARIF t
inner join (select mtar_id, marc_id,mtar_montant from MTARIF where
cast(mtar_datedebut as smalldatetime) !=
cast(convert(varchar(10),@date,103)
as smalldatetime) order by mtar_id desc) a
on t.mtar_marcid=a.mtar_marcid
where cast(mtar_datedebut as
smalldatetime)Êst(convert(varchar(10),@date,103) as smalldatetime)
order by t.mtar_debut asc,t.marc_id asc
Mais cela me retourne deux fois le même tarif (le dernier). J'ai essayé
avec
des TOP et des MAX mais je suis un peu perdu.
Si quelqu'un avait une idée.
Merci par avance
Bonjour,
J'ai un problème d'écriture de requête.
J'ai une table MTARIF avec
MTAR_ID int ID PK autoincrement
MARC_ID int (id de la marchandise pour ce tarif)
MTAR_DATEDEBUT smalldatetime (date de début de validité du tarif)
MTAR_DATEFIN smalldatetime (date de finde validité du tarif)
MTAR_MONTANT decimal(18,2) valeur du tarif
les tarifs changent et peuvent être saisis à l'avance.
Je souhaiterais connaître pour une date donnée le tarif en cours et le
tarif
précédent. EN sachant qu'il peur y avoir plusieurs tarifs précédents et
que
je souhaite le dernier plus proche de la date saisie.
J'ai écrit cette procédure
CREATE PROCEDURE dbo.tarif_liste
@date smalldatetime
a.mtar_id as MTAR_ID
,t.marc_id as marc_id
,convert(varchar(20),t.mtar_datedebut,103) as debut
,t.mtar_montant as nouveauMontant
,a.mtar_montant as ancienMontant
from TARIF t
inner join (select mtar_id, marc_id,mtar_montant from MTARIF where
cast(mtar_datedebut as smalldatetime) !=
cast(convert(varchar(10),@date,103)
as smalldatetime) order by mtar_id desc) a
on t.mtar_marcid=a.mtar_marcid
where cast(mtar_datedebut as
smalldatetime)Êst(convert(varchar(10),@date,103) as smalldatetime)
order by t.mtar_debut asc,t.marc_id asc
Mais cela me retourne deux fois le même tarif (le dernier). J'ai essayé
avec
des TOP et des MAX mais je suis un peu perdu.
Si quelqu'un avait une idée.
Merci par avance
Bonjour,
J'ai un problème d'écriture de requête.
J'ai une table MTARIF avec
MTAR_ID int ID PK autoincrement
MARC_ID int (id de la marchandise pour ce tarif)
MTAR_DATEDEBUT smalldatetime (date de début de validité du tarif)
MTAR_DATEFIN smalldatetime (date de finde validité du tarif)
MTAR_MONTANT decimal(18,2) valeur du tarif
les tarifs changent et peuvent être saisis à l'avance.
Je souhaiterais connaître pour une date donnée le tarif en cours et le
tarif
précédent. EN sachant qu'il peur y avoir plusieurs tarifs précédents et
que
je souhaite le dernier plus proche de la date saisie.
J'ai écrit cette procédure
CREATE PROCEDURE dbo.tarif_liste
@date smalldatetime
a.mtar_id as MTAR_ID
,t.marc_id as marc_id
,convert(varchar(20),t.mtar_datedebut,103) as debut
,t.mtar_montant as nouveauMontant
,a.mtar_montant as ancienMontant
from TARIF t
inner join (select mtar_id, marc_id,mtar_montant from MTARIF where
cast(mtar_datedebut as smalldatetime) !=
cast(convert(varchar(10),@date,103)
as smalldatetime) order by mtar_id desc) a
on t.mtar_marcid=a.mtar_marcid
where cast(mtar_datedebut as
smalldatetime)Êst(convert(varchar(10),@date,103) as smalldatetime)
order by t.mtar_debut asc,t.marc_id asc
Mais cela me retourne deux fois le même tarif (le dernier). J'ai essayé
avec
des TOP et des MAX mais je suis un peu perdu.
Si quelqu'un avait une idée.
Merci par avance
Si tu pouvais fournir un DDL et quelques données, cela faciliterait l'aide
--
Bien Cordialement
Med Bouchenafa
"jerome" wrote in message
news:
> Bonjour,
>
> J'ai un problème d'écriture de requête.
> J'ai une table MTARIF avec
> MTAR_ID int ID PK autoincrement
> MARC_ID int (id de la marchandise pour ce tarif)
> MTAR_DATEDEBUT smalldatetime (date de début de validité du tarif)
> MTAR_DATEFIN smalldatetime (date de finde validité du tarif)
> MTAR_MONTANT decimal(18,2) valeur du tarif
>
> les tarifs changent et peuvent être saisis à l'avance.
>
> Je souhaiterais connaître pour une date donnée le tarif en cours et le
> tarif
> précédent. EN sachant qu'il peur y avoir plusieurs tarifs précédents et
> que
> je souhaite le dernier plus proche de la date saisie.
>
> J'ai écrit cette procédure
>
> CREATE PROCEDURE dbo.tarif_liste
> @date smalldatetime
>
> a.mtar_id as MTAR_ID
> ,t.marc_id as marc_id
> ,convert(varchar(20),t.mtar_datedebut,103) as debut
> ,t.mtar_montant as nouveauMontant
> ,a.mtar_montant as ancienMontant
>
>
> from TARIF t
>
> inner join (select mtar_id, marc_id,mtar_montant from MTARIF where
> cast(mtar_datedebut as smalldatetime) ! > > cast(convert(varchar(10),@date,103)
> as smalldatetime) order by mtar_id desc) a
> on t.mtar_marcid=a.mtar_marcid
>
> where cast(mtar_datedebut as
> smalldatetime)Êst(convert(varchar(10),@date,103) as smalldatetime)
>
> order by t.mtar_debut asc,t.marc_id asc
>
>
> Mais cela me retourne deux fois le même tarif (le dernier). J'ai essayé
> avec
> des TOP et des MAX mais je suis un peu perdu.
>
> Si quelqu'un avait une idée.
>
> Merci par avance
>
>
Si tu pouvais fournir un DDL et quelques données, cela faciliterait l'aide
--
Bien Cordialement
Med Bouchenafa
"jerome" <jerome.b@nospam.fr> wrote in message
news:uln8LlS1JHA.4416@TK2MSFTNGP05.phx.gbl...
> Bonjour,
>
> J'ai un problème d'écriture de requête.
> J'ai une table MTARIF avec
> MTAR_ID int ID PK autoincrement
> MARC_ID int (id de la marchandise pour ce tarif)
> MTAR_DATEDEBUT smalldatetime (date de début de validité du tarif)
> MTAR_DATEFIN smalldatetime (date de finde validité du tarif)
> MTAR_MONTANT decimal(18,2) valeur du tarif
>
> les tarifs changent et peuvent être saisis à l'avance.
>
> Je souhaiterais connaître pour une date donnée le tarif en cours et le
> tarif
> précédent. EN sachant qu'il peur y avoir plusieurs tarifs précédents et
> que
> je souhaite le dernier plus proche de la date saisie.
>
> J'ai écrit cette procédure
>
> CREATE PROCEDURE dbo.tarif_liste
> @date smalldatetime
>
> a.mtar_id as MTAR_ID
> ,t.marc_id as marc_id
> ,convert(varchar(20),t.mtar_datedebut,103) as debut
> ,t.mtar_montant as nouveauMontant
> ,a.mtar_montant as ancienMontant
>
>
> from TARIF t
>
> inner join (select mtar_id, marc_id,mtar_montant from MTARIF where
> cast(mtar_datedebut as smalldatetime) ! > > cast(convert(varchar(10),@date,103)
> as smalldatetime) order by mtar_id desc) a
> on t.mtar_marcid=a.mtar_marcid
>
> where cast(mtar_datedebut as
> smalldatetime)Êst(convert(varchar(10),@date,103) as smalldatetime)
>
> order by t.mtar_debut asc,t.marc_id asc
>
>
> Mais cela me retourne deux fois le même tarif (le dernier). J'ai essayé
> avec
> des TOP et des MAX mais je suis un peu perdu.
>
> Si quelqu'un avait une idée.
>
> Merci par avance
>
>
Si tu pouvais fournir un DDL et quelques données, cela faciliterait l'aide
--
Bien Cordialement
Med Bouchenafa
"jerome" wrote in message
news:
> Bonjour,
>
> J'ai un problème d'écriture de requête.
> J'ai une table MTARIF avec
> MTAR_ID int ID PK autoincrement
> MARC_ID int (id de la marchandise pour ce tarif)
> MTAR_DATEDEBUT smalldatetime (date de début de validité du tarif)
> MTAR_DATEFIN smalldatetime (date de finde validité du tarif)
> MTAR_MONTANT decimal(18,2) valeur du tarif
>
> les tarifs changent et peuvent être saisis à l'avance.
>
> Je souhaiterais connaître pour une date donnée le tarif en cours et le
> tarif
> précédent. EN sachant qu'il peur y avoir plusieurs tarifs précédents et
> que
> je souhaite le dernier plus proche de la date saisie.
>
> J'ai écrit cette procédure
>
> CREATE PROCEDURE dbo.tarif_liste
> @date smalldatetime
>
> a.mtar_id as MTAR_ID
> ,t.marc_id as marc_id
> ,convert(varchar(20),t.mtar_datedebut,103) as debut
> ,t.mtar_montant as nouveauMontant
> ,a.mtar_montant as ancienMontant
>
>
> from TARIF t
>
> inner join (select mtar_id, marc_id,mtar_montant from MTARIF where
> cast(mtar_datedebut as smalldatetime) ! > > cast(convert(varchar(10),@date,103)
> as smalldatetime) order by mtar_id desc) a
> on t.mtar_marcid=a.mtar_marcid
>
> where cast(mtar_datedebut as
> smalldatetime)Êst(convert(varchar(10),@date,103) as smalldatetime)
>
> order by t.mtar_debut asc,t.marc_id asc
>
>
> Mais cela me retourne deux fois le même tarif (le dernier). J'ai essayé
> avec
> des TOP et des MAX mais je suis un peu perdu.
>
> Si quelqu'un avait une idée.
>
> Merci par avance
>
>
J'espère que cela ira comme ça.
Merci par avance
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
SET ANSI_PADDING ON
GO
CREATE TABLE [dbo].[MTARIF](
[MTAR_ID] [int] IDENTITY(1,1) NOT NULL,
[MTAR_MARCID] [int] NOT NULL,
[MTAR_PRIXTARIF] [decimal](18, 2) NULL,
[MTAR_DEBUT] [datetime] NULL,
[MTAR_FIN] [datetime] NULL,
[MTAR_DATECREATION] [datetime] NULL CONSTRAINT [DF_MTARIF_MTAR_CREATION]
DEFAULT (getdate()),
[MTAR_MODIFICATION] [datetime] NULL,
CONSTRAINT [PK_MTARIF] PRIMARY KEY CLUSTERED
(
[MTAR_ID] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY > OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY]
GO
SET ANSI_PADDING OFF
insert into mtarif (mtar_marcid,mtar_prixtarif,mtar_debut,mtar_fin)
values (1,20,'01/01/2009','01/04/2009')
GO
insert into mtarif (mtar_marcid,mtar_prixtarif,mtar_debut,mtar_fin)
values (2,10,'01/01/2009','01/01/2010')
GO
insert into mtarif (mtar_marcid,mtar_prixtarif,mtar_debut,mtar_fin)
values (1,22,'02/04/2009','01/06/2009')
GO
insert into mtarif (mtar_marcid,mtar_prixtarif,mtar_debut,mtar_fin)
values (1,25,'02/06/2009','01/01/2010')
GO
insert into mtarif (mtar_marcid,mtar_prixtarif,mtar_debut,mtar_fin)
values (2,5,'01/01/2009','01/06/2009')
GO
insert into mtarif (mtar_marcid,mtar_prixtarif,mtar_debut,mtar_fin)
values (2,8,'02/06/2009','01/01/2100')
GO
insert into mtarif (mtar_marcid,mtar_prixtarif,mtar_debut,mtar_fin)
values (3,100,'01/01/2009','01/01/2100')
GO
"Med Bouchenafa" wrote in message
news:Si tu pouvais fournir un DDL et quelques données, cela faciliterait
l'aide
--
Bien Cordialement
Med Bouchenafa
"jerome" wrote in message
news:
> Bonjour,
>
> J'ai un problème d'écriture de requête.
> J'ai une table MTARIF avec
> MTAR_ID int ID PK autoincrement
> MARC_ID int (id de la marchandise pour ce tarif)
> MTAR_DATEDEBUT smalldatetime (date de début de validité du tarif)
> MTAR_DATEFIN smalldatetime (date de finde validité du tarif)
> MTAR_MONTANT decimal(18,2) valeur du tarif
>
> les tarifs changent et peuvent être saisis à l'avance.
>
> Je souhaiterais connaître pour une date donnée le tarif en cours et le
> tarif
> précédent. EN sachant qu'il peur y avoir plusieurs tarifs précédents et
> que
> je souhaite le dernier plus proche de la date saisie.
>
> J'ai écrit cette procédure
>
> CREATE PROCEDURE dbo.tarif_liste
> @date smalldatetime
>
> a.mtar_id as MTAR_ID
> ,t.marc_id as marc_id
> ,convert(varchar(20),t.mtar_datedebut,103) as debut
> ,t.mtar_montant as nouveauMontant
> ,a.mtar_montant as ancienMontant
>
>
> from TARIF t
>
> inner join (select mtar_id, marc_id,mtar_montant from MTARIF where
> cast(mtar_datedebut as smalldatetime) ! >> > cast(convert(varchar(10),@date,103)
> as smalldatetime) order by mtar_id desc) a
> on t.mtar_marcid=a.mtar_marcid
>
> where cast(mtar_datedebut as
> smalldatetime)Êst(convert(varchar(10),@date,103) as smalldatetime)
>
> order by t.mtar_debut asc,t.marc_id asc
>
>
> Mais cela me retourne deux fois le même tarif (le dernier). J'ai essayé
> avec
> des TOP et des MAX mais je suis un peu perdu.
>
> Si quelqu'un avait une idée.
>
> Merci par avance
>
>
J'espère que cela ira comme ça.
Merci par avance
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
SET ANSI_PADDING ON
GO
CREATE TABLE [dbo].[MTARIF](
[MTAR_ID] [int] IDENTITY(1,1) NOT NULL,
[MTAR_MARCID] [int] NOT NULL,
[MTAR_PRIXTARIF] [decimal](18, 2) NULL,
[MTAR_DEBUT] [datetime] NULL,
[MTAR_FIN] [datetime] NULL,
[MTAR_DATECREATION] [datetime] NULL CONSTRAINT [DF_MTARIF_MTAR_CREATION]
DEFAULT (getdate()),
[MTAR_MODIFICATION] [datetime] NULL,
CONSTRAINT [PK_MTARIF] PRIMARY KEY CLUSTERED
(
[MTAR_ID] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY > OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY]
GO
SET ANSI_PADDING OFF
insert into mtarif (mtar_marcid,mtar_prixtarif,mtar_debut,mtar_fin)
values (1,20,'01/01/2009','01/04/2009')
GO
insert into mtarif (mtar_marcid,mtar_prixtarif,mtar_debut,mtar_fin)
values (2,10,'01/01/2009','01/01/2010')
GO
insert into mtarif (mtar_marcid,mtar_prixtarif,mtar_debut,mtar_fin)
values (1,22,'02/04/2009','01/06/2009')
GO
insert into mtarif (mtar_marcid,mtar_prixtarif,mtar_debut,mtar_fin)
values (1,25,'02/06/2009','01/01/2010')
GO
insert into mtarif (mtar_marcid,mtar_prixtarif,mtar_debut,mtar_fin)
values (2,5,'01/01/2009','01/06/2009')
GO
insert into mtarif (mtar_marcid,mtar_prixtarif,mtar_debut,mtar_fin)
values (2,8,'02/06/2009','01/01/2100')
GO
insert into mtarif (mtar_marcid,mtar_prixtarif,mtar_debut,mtar_fin)
values (3,100,'01/01/2009','01/01/2100')
GO
"Med Bouchenafa" <com.hotmail@bouchenafa> wrote in message
news:u54FdnU1JHA.1716@TK2MSFTNGP03.phx.gbl...
Si tu pouvais fournir un DDL et quelques données, cela faciliterait
l'aide
--
Bien Cordialement
Med Bouchenafa
"jerome" <jerome.b@nospam.fr> wrote in message
news:uln8LlS1JHA.4416@TK2MSFTNGP05.phx.gbl...
> Bonjour,
>
> J'ai un problème d'écriture de requête.
> J'ai une table MTARIF avec
> MTAR_ID int ID PK autoincrement
> MARC_ID int (id de la marchandise pour ce tarif)
> MTAR_DATEDEBUT smalldatetime (date de début de validité du tarif)
> MTAR_DATEFIN smalldatetime (date de finde validité du tarif)
> MTAR_MONTANT decimal(18,2) valeur du tarif
>
> les tarifs changent et peuvent être saisis à l'avance.
>
> Je souhaiterais connaître pour une date donnée le tarif en cours et le
> tarif
> précédent. EN sachant qu'il peur y avoir plusieurs tarifs précédents et
> que
> je souhaite le dernier plus proche de la date saisie.
>
> J'ai écrit cette procédure
>
> CREATE PROCEDURE dbo.tarif_liste
> @date smalldatetime
>
> a.mtar_id as MTAR_ID
> ,t.marc_id as marc_id
> ,convert(varchar(20),t.mtar_datedebut,103) as debut
> ,t.mtar_montant as nouveauMontant
> ,a.mtar_montant as ancienMontant
>
>
> from TARIF t
>
> inner join (select mtar_id, marc_id,mtar_montant from MTARIF where
> cast(mtar_datedebut as smalldatetime) ! >> > cast(convert(varchar(10),@date,103)
> as smalldatetime) order by mtar_id desc) a
> on t.mtar_marcid=a.mtar_marcid
>
> where cast(mtar_datedebut as
> smalldatetime)Êst(convert(varchar(10),@date,103) as smalldatetime)
>
> order by t.mtar_debut asc,t.marc_id asc
>
>
> Mais cela me retourne deux fois le même tarif (le dernier). J'ai essayé
> avec
> des TOP et des MAX mais je suis un peu perdu.
>
> Si quelqu'un avait une idée.
>
> Merci par avance
>
>
J'espère que cela ira comme ça.
Merci par avance
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
SET ANSI_PADDING ON
GO
CREATE TABLE [dbo].[MTARIF](
[MTAR_ID] [int] IDENTITY(1,1) NOT NULL,
[MTAR_MARCID] [int] NOT NULL,
[MTAR_PRIXTARIF] [decimal](18, 2) NULL,
[MTAR_DEBUT] [datetime] NULL,
[MTAR_FIN] [datetime] NULL,
[MTAR_DATECREATION] [datetime] NULL CONSTRAINT [DF_MTARIF_MTAR_CREATION]
DEFAULT (getdate()),
[MTAR_MODIFICATION] [datetime] NULL,
CONSTRAINT [PK_MTARIF] PRIMARY KEY CLUSTERED
(
[MTAR_ID] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY > OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY]
GO
SET ANSI_PADDING OFF
insert into mtarif (mtar_marcid,mtar_prixtarif,mtar_debut,mtar_fin)
values (1,20,'01/01/2009','01/04/2009')
GO
insert into mtarif (mtar_marcid,mtar_prixtarif,mtar_debut,mtar_fin)
values (2,10,'01/01/2009','01/01/2010')
GO
insert into mtarif (mtar_marcid,mtar_prixtarif,mtar_debut,mtar_fin)
values (1,22,'02/04/2009','01/06/2009')
GO
insert into mtarif (mtar_marcid,mtar_prixtarif,mtar_debut,mtar_fin)
values (1,25,'02/06/2009','01/01/2010')
GO
insert into mtarif (mtar_marcid,mtar_prixtarif,mtar_debut,mtar_fin)
values (2,5,'01/01/2009','01/06/2009')
GO
insert into mtarif (mtar_marcid,mtar_prixtarif,mtar_debut,mtar_fin)
values (2,8,'02/06/2009','01/01/2100')
GO
insert into mtarif (mtar_marcid,mtar_prixtarif,mtar_debut,mtar_fin)
values (3,100,'01/01/2009','01/01/2100')
GO
"Med Bouchenafa" wrote in message
news:Si tu pouvais fournir un DDL et quelques données, cela faciliterait
l'aide
--
Bien Cordialement
Med Bouchenafa
"jerome" wrote in message
news:
> Bonjour,
>
> J'ai un problème d'écriture de requête.
> J'ai une table MTARIF avec
> MTAR_ID int ID PK autoincrement
> MARC_ID int (id de la marchandise pour ce tarif)
> MTAR_DATEDEBUT smalldatetime (date de début de validité du tarif)
> MTAR_DATEFIN smalldatetime (date de finde validité du tarif)
> MTAR_MONTANT decimal(18,2) valeur du tarif
>
> les tarifs changent et peuvent être saisis à l'avance.
>
> Je souhaiterais connaître pour une date donnée le tarif en cours et le
> tarif
> précédent. EN sachant qu'il peur y avoir plusieurs tarifs précédents et
> que
> je souhaite le dernier plus proche de la date saisie.
>
> J'ai écrit cette procédure
>
> CREATE PROCEDURE dbo.tarif_liste
> @date smalldatetime
>
> a.mtar_id as MTAR_ID
> ,t.marc_id as marc_id
> ,convert(varchar(20),t.mtar_datedebut,103) as debut
> ,t.mtar_montant as nouveauMontant
> ,a.mtar_montant as ancienMontant
>
>
> from TARIF t
>
> inner join (select mtar_id, marc_id,mtar_montant from MTARIF where
> cast(mtar_datedebut as smalldatetime) ! >> > cast(convert(varchar(10),@date,103)
> as smalldatetime) order by mtar_id desc) a
> on t.mtar_marcid=a.mtar_marcid
>
> where cast(mtar_datedebut as
> smalldatetime)Êst(convert(varchar(10),@date,103) as smalldatetime)
>
> order by t.mtar_debut asc,t.marc_id asc
>
>
> Mais cela me retourne deux fois le même tarif (le dernier). J'ai essayé
> avec
> des TOP et des MAX mais je suis un peu perdu.
>
> Si quelqu'un avait une idée.
>
> Merci par avance
>
>
DECLARE @DateTemoin DATETIME
SET @DateTemoin = '20090112'
;WITH PriceCTE AS
(
SELECT MTAR_ID,
MTAR_MARCID,
MTAR_DEBUT,
MTAR_FIN,
MTAR_PRIXTARIF,
rowNum = ROW_NUMBER() OVER (Partition BY MTAR_MARCID
BY MTAR_DEBUT)
FROM MTARIF
)
SELECT C.MTAR_ID,
C.MTAR_MARCID,
C.MTAR_DEBUT,
C.MTAR_FIN,
CurrentPrice = C.MTAR_PRIXTARIF,
PreviousPrice = P.MTAR_PRIXTARIF
FROM PriceCTE C LEFT JOIN PriceCTE P ON C.rowNum = P.rowNum + 1 AND
C.MTAR_MARCID = P.MTAR_MARCID
WHERE @DateTemoin BETWEEN C.MTAR_DEBUT AND C.MTAR_FIN
--
Bien Cordialement
Med Bouchenafa
"jerome" wrote in message
news:%
> J'espère que cela ira comme ça.
>
> Merci par avance
>
>
> SET ANSI_NULLS ON
> GO
> SET QUOTED_IDENTIFIER ON
> GO
> SET ANSI_PADDING ON
> GO
> CREATE TABLE [dbo].[MTARIF](
> [MTAR_ID] [int] IDENTITY(1,1) NOT NULL,
> [MTAR_MARCID] [int] NOT NULL,
> [MTAR_PRIXTARIF] [decimal](18, 2) NULL,
> [MTAR_DEBUT] [datetime] NULL,
> [MTAR_FIN] [datetime] NULL,
> [MTAR_DATECREATION] [datetime] NULL CONSTRAINT [DF_MTARIF_MTAR_CREATION]
> DEFAULT (getdate()),
> [MTAR_MODIFICATION] [datetime] NULL,
> CONSTRAINT [PK_MTARIF] PRIMARY KEY CLUSTERED
> (
> [MTAR_ID] ASC
> )WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY > > OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
> ) ON [PRIMARY]
>
> GO
> SET ANSI_PADDING OFF
>
>
> insert into mtarif (mtar_marcid,mtar_prixtarif,mtar_debut,mtar_fin)
> values (1,20,'01/01/2009','01/04/2009')
> GO
>
> insert into mtarif (mtar_marcid,mtar_prixtarif,mtar_debut,mtar_fin)
> values (2,10,'01/01/2009','01/01/2010')
> GO
>
> insert into mtarif (mtar_marcid,mtar_prixtarif,mtar_debut,mtar_fin)
> values (1,22,'02/04/2009','01/06/2009')
> GO
>
> insert into mtarif (mtar_marcid,mtar_prixtarif,mtar_debut,mtar_fin)
> values (1,25,'02/06/2009','01/01/2010')
> GO
>
> insert into mtarif (mtar_marcid,mtar_prixtarif,mtar_debut,mtar_fin)
> values (2,5,'01/01/2009','01/06/2009')
> GO
>
> insert into mtarif (mtar_marcid,mtar_prixtarif,mtar_debut,mtar_fin)
> values (2,8,'02/06/2009','01/01/2100')
> GO
>
> insert into mtarif (mtar_marcid,mtar_prixtarif,mtar_debut,mtar_fin)
> values (3,100,'01/01/2009','01/01/2100')
> GO
>
> "Med Bouchenafa" wrote in message
> news:
>> Si tu pouvais fournir un DDL et quelques données, cela faciliterait
>> l'aide
>>
>> --
>> Bien Cordialement
>> Med Bouchenafa
>>
>> "jerome" wrote in message
>> news:
>> > Bonjour,
>> >
>> > J'ai un problème d'écriture de requête.
>> > J'ai une table MTARIF avec
>> > MTAR_ID int ID PK autoincrement
>> > MARC_ID int (id de la marchandise pour ce tarif)
>> > MTAR_DATEDEBUT smalldatetime (date de début de validité du tarif)
>> > MTAR_DATEFIN smalldatetime (date de finde validité du tarif)
>> > MTAR_MONTANT decimal(18,2) valeur du tarif
>> >
>> > les tarifs changent et peuvent être saisis à l'avance.
>> >
>> > Je souhaiterais connaître pour une date donnée le tarif en cours et
>> > tarif
>> > précédent. EN sachant qu'il peur y avoir plusieurs tarifs précédents
>> > que
>> > je souhaite le dernier plus proche de la date saisie.
>> >
>> > J'ai écrit cette procédure
>> >
>> > CREATE PROCEDURE dbo.tarif_liste
>> > @date smalldatetime
>> >
>> > a.mtar_id as MTAR_ID
>> > ,t.marc_id as marc_id
>> > ,convert(varchar(20),t.mtar_datedebut,103) as debut
>> > ,t.mtar_montant as nouveauMontant
>> > ,a.mtar_montant as ancienMontant
>> >
>> >
>> > from TARIF t
>> >
>> > inner join (select mtar_id, marc_id,mtar_montant from MTARIF where
>> > cast(mtar_datedebut as smalldatetime) ! > >> > cast(convert(varchar(10),@date,103)
>> > as smalldatetime) order by mtar_id desc) a
>> > on t.mtar_marcid=a.mtar_marcid
>> >
>> > where cast(mtar_datedebut as
>> > smalldatetime)Êst(convert(varchar(10),@date,103) as smalldatetime)
>> >
>> > order by t.mtar_debut asc,t.marc_id asc
>> >
>> >
>> > Mais cela me retourne deux fois le même tarif (le dernier). J'ai
>> > avec
>> > des TOP et des MAX mais je suis un peu perdu.
>> >
>> > Si quelqu'un avait une idée.
>> >
>> > Merci par avance
>> >
>> >
>>
>
>
DECLARE @DateTemoin DATETIME
SET @DateTemoin = '20090112'
;WITH PriceCTE AS
(
SELECT MTAR_ID,
MTAR_MARCID,
MTAR_DEBUT,
MTAR_FIN,
MTAR_PRIXTARIF,
rowNum = ROW_NUMBER() OVER (Partition BY MTAR_MARCID
BY MTAR_DEBUT)
FROM MTARIF
)
SELECT C.MTAR_ID,
C.MTAR_MARCID,
C.MTAR_DEBUT,
C.MTAR_FIN,
CurrentPrice = C.MTAR_PRIXTARIF,
PreviousPrice = P.MTAR_PRIXTARIF
FROM PriceCTE C LEFT JOIN PriceCTE P ON C.rowNum = P.rowNum + 1 AND
C.MTAR_MARCID = P.MTAR_MARCID
WHERE @DateTemoin BETWEEN C.MTAR_DEBUT AND C.MTAR_FIN
--
Bien Cordialement
Med Bouchenafa
"jerome" <jerome.b@nospam.fr> wrote in message
news:%23J07kwV1JHA.1416@TK2MSFTNGP04.phx.gbl...
> J'espère que cela ira comme ça.
>
> Merci par avance
>
>
> SET ANSI_NULLS ON
> GO
> SET QUOTED_IDENTIFIER ON
> GO
> SET ANSI_PADDING ON
> GO
> CREATE TABLE [dbo].[MTARIF](
> [MTAR_ID] [int] IDENTITY(1,1) NOT NULL,
> [MTAR_MARCID] [int] NOT NULL,
> [MTAR_PRIXTARIF] [decimal](18, 2) NULL,
> [MTAR_DEBUT] [datetime] NULL,
> [MTAR_FIN] [datetime] NULL,
> [MTAR_DATECREATION] [datetime] NULL CONSTRAINT [DF_MTARIF_MTAR_CREATION]
> DEFAULT (getdate()),
> [MTAR_MODIFICATION] [datetime] NULL,
> CONSTRAINT [PK_MTARIF] PRIMARY KEY CLUSTERED
> (
> [MTAR_ID] ASC
> )WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY > > OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
> ) ON [PRIMARY]
>
> GO
> SET ANSI_PADDING OFF
>
>
> insert into mtarif (mtar_marcid,mtar_prixtarif,mtar_debut,mtar_fin)
> values (1,20,'01/01/2009','01/04/2009')
> GO
>
> insert into mtarif (mtar_marcid,mtar_prixtarif,mtar_debut,mtar_fin)
> values (2,10,'01/01/2009','01/01/2010')
> GO
>
> insert into mtarif (mtar_marcid,mtar_prixtarif,mtar_debut,mtar_fin)
> values (1,22,'02/04/2009','01/06/2009')
> GO
>
> insert into mtarif (mtar_marcid,mtar_prixtarif,mtar_debut,mtar_fin)
> values (1,25,'02/06/2009','01/01/2010')
> GO
>
> insert into mtarif (mtar_marcid,mtar_prixtarif,mtar_debut,mtar_fin)
> values (2,5,'01/01/2009','01/06/2009')
> GO
>
> insert into mtarif (mtar_marcid,mtar_prixtarif,mtar_debut,mtar_fin)
> values (2,8,'02/06/2009','01/01/2100')
> GO
>
> insert into mtarif (mtar_marcid,mtar_prixtarif,mtar_debut,mtar_fin)
> values (3,100,'01/01/2009','01/01/2100')
> GO
>
> "Med Bouchenafa" <com.hotmail@bouchenafa> wrote in message
> news:u54FdnU1JHA.1716@TK2MSFTNGP03.phx.gbl...
>> Si tu pouvais fournir un DDL et quelques données, cela faciliterait
>> l'aide
>>
>> --
>> Bien Cordialement
>> Med Bouchenafa
>>
>> "jerome" <jerome.b@nospam.fr> wrote in message
>> news:uln8LlS1JHA.4416@TK2MSFTNGP05.phx.gbl...
>> > Bonjour,
>> >
>> > J'ai un problème d'écriture de requête.
>> > J'ai une table MTARIF avec
>> > MTAR_ID int ID PK autoincrement
>> > MARC_ID int (id de la marchandise pour ce tarif)
>> > MTAR_DATEDEBUT smalldatetime (date de début de validité du tarif)
>> > MTAR_DATEFIN smalldatetime (date de finde validité du tarif)
>> > MTAR_MONTANT decimal(18,2) valeur du tarif
>> >
>> > les tarifs changent et peuvent être saisis à l'avance.
>> >
>> > Je souhaiterais connaître pour une date donnée le tarif en cours et
>> > tarif
>> > précédent. EN sachant qu'il peur y avoir plusieurs tarifs précédents
>> > que
>> > je souhaite le dernier plus proche de la date saisie.
>> >
>> > J'ai écrit cette procédure
>> >
>> > CREATE PROCEDURE dbo.tarif_liste
>> > @date smalldatetime
>> >
>> > a.mtar_id as MTAR_ID
>> > ,t.marc_id as marc_id
>> > ,convert(varchar(20),t.mtar_datedebut,103) as debut
>> > ,t.mtar_montant as nouveauMontant
>> > ,a.mtar_montant as ancienMontant
>> >
>> >
>> > from TARIF t
>> >
>> > inner join (select mtar_id, marc_id,mtar_montant from MTARIF where
>> > cast(mtar_datedebut as smalldatetime) ! > >> > cast(convert(varchar(10),@date,103)
>> > as smalldatetime) order by mtar_id desc) a
>> > on t.mtar_marcid=a.mtar_marcid
>> >
>> > where cast(mtar_datedebut as
>> > smalldatetime)Êst(convert(varchar(10),@date,103) as smalldatetime)
>> >
>> > order by t.mtar_debut asc,t.marc_id asc
>> >
>> >
>> > Mais cela me retourne deux fois le même tarif (le dernier). J'ai
>> > avec
>> > des TOP et des MAX mais je suis un peu perdu.
>> >
>> > Si quelqu'un avait une idée.
>> >
>> > Merci par avance
>> >
>> >
>>
>
>
DECLARE @DateTemoin DATETIME
SET @DateTemoin = '20090112'
;WITH PriceCTE AS
(
SELECT MTAR_ID,
MTAR_MARCID,
MTAR_DEBUT,
MTAR_FIN,
MTAR_PRIXTARIF,
rowNum = ROW_NUMBER() OVER (Partition BY MTAR_MARCID
BY MTAR_DEBUT)
FROM MTARIF
)
SELECT C.MTAR_ID,
C.MTAR_MARCID,
C.MTAR_DEBUT,
C.MTAR_FIN,
CurrentPrice = C.MTAR_PRIXTARIF,
PreviousPrice = P.MTAR_PRIXTARIF
FROM PriceCTE C LEFT JOIN PriceCTE P ON C.rowNum = P.rowNum + 1 AND
C.MTAR_MARCID = P.MTAR_MARCID
WHERE @DateTemoin BETWEEN C.MTAR_DEBUT AND C.MTAR_FIN
--
Bien Cordialement
Med Bouchenafa
"jerome" wrote in message
news:%
> J'espère que cela ira comme ça.
>
> Merci par avance
>
>
> SET ANSI_NULLS ON
> GO
> SET QUOTED_IDENTIFIER ON
> GO
> SET ANSI_PADDING ON
> GO
> CREATE TABLE [dbo].[MTARIF](
> [MTAR_ID] [int] IDENTITY(1,1) NOT NULL,
> [MTAR_MARCID] [int] NOT NULL,
> [MTAR_PRIXTARIF] [decimal](18, 2) NULL,
> [MTAR_DEBUT] [datetime] NULL,
> [MTAR_FIN] [datetime] NULL,
> [MTAR_DATECREATION] [datetime] NULL CONSTRAINT [DF_MTARIF_MTAR_CREATION]
> DEFAULT (getdate()),
> [MTAR_MODIFICATION] [datetime] NULL,
> CONSTRAINT [PK_MTARIF] PRIMARY KEY CLUSTERED
> (
> [MTAR_ID] ASC
> )WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY > > OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
> ) ON [PRIMARY]
>
> GO
> SET ANSI_PADDING OFF
>
>
> insert into mtarif (mtar_marcid,mtar_prixtarif,mtar_debut,mtar_fin)
> values (1,20,'01/01/2009','01/04/2009')
> GO
>
> insert into mtarif (mtar_marcid,mtar_prixtarif,mtar_debut,mtar_fin)
> values (2,10,'01/01/2009','01/01/2010')
> GO
>
> insert into mtarif (mtar_marcid,mtar_prixtarif,mtar_debut,mtar_fin)
> values (1,22,'02/04/2009','01/06/2009')
> GO
>
> insert into mtarif (mtar_marcid,mtar_prixtarif,mtar_debut,mtar_fin)
> values (1,25,'02/06/2009','01/01/2010')
> GO
>
> insert into mtarif (mtar_marcid,mtar_prixtarif,mtar_debut,mtar_fin)
> values (2,5,'01/01/2009','01/06/2009')
> GO
>
> insert into mtarif (mtar_marcid,mtar_prixtarif,mtar_debut,mtar_fin)
> values (2,8,'02/06/2009','01/01/2100')
> GO
>
> insert into mtarif (mtar_marcid,mtar_prixtarif,mtar_debut,mtar_fin)
> values (3,100,'01/01/2009','01/01/2100')
> GO
>
> "Med Bouchenafa" wrote in message
> news:
>> Si tu pouvais fournir un DDL et quelques données, cela faciliterait
>> l'aide
>>
>> --
>> Bien Cordialement
>> Med Bouchenafa
>>
>> "jerome" wrote in message
>> news:
>> > Bonjour,
>> >
>> > J'ai un problème d'écriture de requête.
>> > J'ai une table MTARIF avec
>> > MTAR_ID int ID PK autoincrement
>> > MARC_ID int (id de la marchandise pour ce tarif)
>> > MTAR_DATEDEBUT smalldatetime (date de début de validité du tarif)
>> > MTAR_DATEFIN smalldatetime (date de finde validité du tarif)
>> > MTAR_MONTANT decimal(18,2) valeur du tarif
>> >
>> > les tarifs changent et peuvent être saisis à l'avance.
>> >
>> > Je souhaiterais connaître pour une date donnée le tarif en cours et
>> > tarif
>> > précédent. EN sachant qu'il peur y avoir plusieurs tarifs précédents
>> > que
>> > je souhaite le dernier plus proche de la date saisie.
>> >
>> > J'ai écrit cette procédure
>> >
>> > CREATE PROCEDURE dbo.tarif_liste
>> > @date smalldatetime
>> >
>> > a.mtar_id as MTAR_ID
>> > ,t.marc_id as marc_id
>> > ,convert(varchar(20),t.mtar_datedebut,103) as debut
>> > ,t.mtar_montant as nouveauMontant
>> > ,a.mtar_montant as ancienMontant
>> >
>> >
>> > from TARIF t
>> >
>> > inner join (select mtar_id, marc_id,mtar_montant from MTARIF where
>> > cast(mtar_datedebut as smalldatetime) ! > >> > cast(convert(varchar(10),@date,103)
>> > as smalldatetime) order by mtar_id desc) a
>> > on t.mtar_marcid=a.mtar_marcid
>> >
>> > where cast(mtar_datedebut as
>> > smalldatetime)Êst(convert(varchar(10),@date,103) as smalldatetime)
>> >
>> > order by t.mtar_debut asc,t.marc_id asc
>> >
>> >
>> > Mais cela me retourne deux fois le même tarif (le dernier). J'ai
>> > avec
>> > des TOP et des MAX mais je suis un peu perdu.
>> >
>> > Si quelqu'un avait une idée.
>> >
>> > Merci par avance
>> >
>> >
>>
>
>