PHWinfo banniere

Titres
PORTAIL ANNUAIRE ARTICLES COMPARATEUR HÉBERGEURS DEVIS FORUMS RÉDUCTEUR D'URL
Précédent   PHWinfo > Forums Hébergement > Forum Hébergement serveur > ms.sqlserver.server > placing a quantity field in a monthly "record"
S'inscrire FAQ Membres Recherche Messages du jour Marquer les forums comme lus
placing a quantity field in a monthly "record"

Réponse
 
LinkBack Outils de la discussion
Vieux 18/06/2008, 00h21   #1
SQL Programmer
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut placing a quantity field in a monthly "record"

I was treated very rudely on the SQL Programming message board by someone who
doesnot have all of the facts about my background. Hopefully, there will be
someone here who has some decency and kindness. (Otherwise, I'd continue
posting there.)

Below is my SQL view. I need to have the QUANTITY field from the "THEN
MRPW4060.QUANTITY ELSE 0 END AS [QTY ON ORDER]" clause of the CASE statement
below to be placed within just one record of my table (view).

You see, each record in my view represents a month. The SC020230.DATE1
field, for example, could be "2008-07-01 00:00:00.000'. And, the
MRPW4060.DUEDATE field could be "2008-07-20 00:00:00.000". Therefore, I want
the MRPW4060.QUANTITY field to appear just on that record for July (i.e. the
record for the month of July only). Since the quantity is due in the month
of July, I want the quantity to appear just on that record of rows returned
from my view.

How do I tell SQL to place the quantity due in just that one record for that
month that it is due? I imagine I would have to do some sort of "trim"
statement on the DUEDATE or something.....

Thanks! sqlprogrammer@hotmail.com

select ITEMNMBR as [ITEM],
DATE1 As [FORECAST DATE],
QTYTOFORECOST_I As [FORECAST QTY],
SUM([QTY ON ORDER]) As [TOTAL QTY ON ORDER],
DUEDATE As [DUE DATE],
GETDATE() As [CURRENT DATE]
FROM(
select DISTINCT SC020130.ITEMNMBR,
SC020230.SFLINEITEM_I,
SC020230.DATE1,
SC020230.QTYTOFORECOST_I,
MRPW4060.QUANTITY,
MRPW4060.DUEDATE,
GETDATE() As [CURRENT DATE],
CASE WHEN GETDATE()<=MRPW4060.DUEDATE AND GETDATE()>=SC020230.DATE1
THEN MRPW4060.QUANTITY ELSE 0 END AS [QTY ON ORDER]
from SC020230 As SC020230
JOIN SC020130 As SC020130
on SC020230.SFLINEITEM_I = SC020130.SFLINEITEM_I
JOIN MRPW4060 As MRPW4060
on SC020130.ITEMNMBR = MRPW4060.ITEMNMBR
where SC020230.PLANNAME_I = 'MRP FG1' and SC020130.ITEMNMBR = '89417' and
SOPTYPE = '2') As I
GROUP BY ITEMNMBR,
SFLINEITEM_I,
DATE1,
QTYTOFORECOST_I,
DUEDATE,
QUANTITY
ORDER BY ITEMNMBR ASC
  Réponse avec citation
Vieux 18/06/2008, 01h39   #2
Russell Fields
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: placing a quantity field in a monthly "record"

SQL Programmer,

Yes, there are some rude folks out there, but don't let them chase you away.
(Kind of like you don't let someone honking from behind to cause you to go
through the STOP sign before the way is clear.) So....

Without going through your whole query, for which I would need the table
definitions and some INSERT statements to put in some sample data, perhaps a
simple discussion will .

The derived table (the nested query) named I does not obviously return 1 row
for month

The [QTY ON ORDER] from the derived table I is summed in the outer query as
[TOTAL QTY ON ORDER].

You are grouping on several columns from the derived table I, namely
ITEMNMBR, SFLINEITEM_I, DATE1, QTYTOFORECOST_I, DUEDATE, QUANTITY. So, you
are getting one summed value of [QTY ON ORDER] for each of these groups. If
I understand correctly, this is too small a grouping, but this should be
grouped in such a way that DATE1 is only (for example) the first day of each
month.

So, perhaps in your derived table your could replace:
SC020230.DATE1,
with:
DATEADD(MONTH,DATEDIFF(MONTH,0,SC020230.DATE1),0) AS DATE1,

This would allow your GROUP BY to work with a month level DATE1 instead of a
daily DATE1.

Hope that s,
RLF

PS - At the risk of getting shot at by someone, I will also answer in
..programming.


"SQL Programmer" <SQLProgrammer@discussions.microsoft.com> wrote in message
news:6C64B47F-200C-4ACE-947E-57C77C0EDC67@microsoft.com...
>I was treated very rudely on the SQL Programming message board by someone
>who
> doesnot have all of the facts about my background. Hopefully, there will
> be
> someone here who has some decency and kindness. (Otherwise, I'd continue
> posting there.)
>
> Below is my SQL view. I need to have the QUANTITY field from the "THEN
> MRPW4060.QUANTITY ELSE 0 END AS [QTY ON ORDER]" clause of the CASE
> statement
> below to be placed within just one record of my table (view).
>
> You see, each record in my view represents a month. The SC020230.DATE1
> field, for example, could be "2008-07-01 00:00:00.000'. And, the
> MRPW4060.DUEDATE field could be "2008-07-20 00:00:00.000". Therefore, I
> want
> the MRPW4060.QUANTITY field to appear just on that record for July (i.e.
> the
> record for the month of July only). Since the quantity is due in the
> month
> of July, I want the quantity to appear just on that record of rows
> returned
> from my view.
>
> How do I tell SQL to place the quantity due in just that one record for
> that
> month that it is due? I imagine I would have to do some sort of "trim"
> statement on the DUEDATE or something.....
>
> Thanks! sqlprogrammer@hotmail.com
>
> select ITEMNMBR as [ITEM],
> DATE1 As [FORECAST DATE],
> QTYTOFORECOST_I As [FORECAST QTY],
> SUM([QTY ON ORDER]) As [TOTAL QTY ON ORDER],
> DUEDATE As [DUE DATE],
> GETDATE() As [CURRENT DATE]
> FROM(
> select DISTINCT SC020130.ITEMNMBR,
> SC020230.SFLINEITEM_I,
> SC020230.DATE1,
> SC020230.QTYTOFORECOST_I,
> MRPW4060.QUANTITY,
> MRPW4060.DUEDATE,
> GETDATE() As [CURRENT DATE],
> CASE WHEN GETDATE()<=MRPW4060.DUEDATE AND GETDATE()>=SC020230.DATE1
> THEN MRPW4060.QUANTITY ELSE 0 END AS [QTY ON ORDER]
> from SC020230 As SC020230
> JOIN SC020130 As SC020130
> on SC020230.SFLINEITEM_I = SC020130.SFLINEITEM_I
> JOIN MRPW4060 As MRPW4060
> on SC020130.ITEMNMBR = MRPW4060.ITEMNMBR
> where SC020230.PLANNAME_I = 'MRP FG1' and SC020130.ITEMNMBR = '89417' and
> SOPTYPE = '2') As I
> GROUP BY ITEMNMBR,
> SFLINEITEM_I,
> DATE1,
> QTYTOFORECOST_I,
> DUEDATE,
> QUANTITY
> ORDER BY ITEMNMBR ASC



  Réponse avec citation
Vieux 18/06/2008, 02h46   #3
SQL Programmer
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: placing a quantity field in a monthly "record"

Thank you so much, Russell, for your kindness!

SQL Programmer

"Russell Fields" wrote:

> SQL Programmer,
>
> Yes, there are some rude folks out there, but don't let them chase you away.
> (Kind of like you don't let someone honking from behind to cause you to go
> through the STOP sign before the way is clear.) So....
>
> Without going through your whole query, for which I would need the table
> definitions and some INSERT statements to put in some sample data, perhaps a
> simple discussion will .
>
> The derived table (the nested query) named I does not obviously return 1 row
> for month
>
> The [QTY ON ORDER] from the derived table I is summed in the outer query as
> [TOTAL QTY ON ORDER].
>
> You are grouping on several columns from the derived table I, namely
> ITEMNMBR, SFLINEITEM_I, DATE1, QTYTOFORECOST_I, DUEDATE, QUANTITY. So, you
> are getting one summed value of [QTY ON ORDER] for each of these groups. If
> I understand correctly, this is too small a grouping, but this should be
> grouped in such a way that DATE1 is only (for example) the first day of each
> month.
>
> So, perhaps in your derived table your could replace:
> SC020230.DATE1,
> with:
> DATEADD(MONTH,DATEDIFF(MONTH,0,SC020230.DATE1),0) AS DATE1,
>
> This would allow your GROUP BY to work with a month level DATE1 instead of a
> daily DATE1.
>
> Hope that s,
> RLF
>
> PS - At the risk of getting shot at by someone, I will also answer in
> ..programming.
>
>
> "SQL Programmer" <SQLProgrammer@discussions.microsoft.com> wrote in message
> news:6C64B47F-200C-4ACE-947E-57C77C0EDC67@microsoft.com...
> >I was treated very rudely on the SQL Programming message board by someone
> >who
> > doesnot have all of the facts about my background. Hopefully, there will
> > be
> > someone here who has some decency and kindness. (Otherwise, I'd continue
> > posting there.)
> >
> > Below is my SQL view. I need to have the QUANTITY field from the "THEN
> > MRPW4060.QUANTITY ELSE 0 END AS [QTY ON ORDER]" clause of the CASE
> > statement
> > below to be placed within just one record of my table (view).
> >
> > You see, each record in my view represents a month. The SC020230.DATE1
> > field, for example, could be "2008-07-01 00:00:00.000'. And, the
> > MRPW4060.DUEDATE field could be "2008-07-20 00:00:00.000". Therefore, I
> > want
> > the MRPW4060.QUANTITY field to appear just on that record for July (i.e.
> > the
> > record for the month of July only). Since the quantity is due in the
> > month
> > of July, I want the quantity to appear just on that record of rows
> > returned
> > from my view.
> >
> > How do I tell SQL to place the quantity due in just that one record for
> > that
> > month that it is due? I imagine I would have to do some sort of "trim"
> > statement on the DUEDATE or something.....
> >
> > Thanks! sqlprogrammer@hotmail.com
> >
> > select ITEMNMBR as [ITEM],
> > DATE1 As [FORECAST DATE],
> > QTYTOFORECOST_I As [FORECAST QTY],
> > SUM([QTY ON ORDER]) As [TOTAL QTY ON ORDER],
> > DUEDATE As [DUE DATE],
> > GETDATE() As [CURRENT DATE]
> > FROM(
> > select DISTINCT SC020130.ITEMNMBR,
> > SC020230.SFLINEITEM_I,
> > SC020230.DATE1,
> > SC020230.QTYTOFORECOST_I,
> > MRPW4060.QUANTITY,
> > MRPW4060.DUEDATE,
> > GETDATE() As [CURRENT DATE],
> > CASE WHEN GETDATE()<=MRPW4060.DUEDATE AND GETDATE()>=SC020230.DATE1
> > THEN MRPW4060.QUANTITY ELSE 0 END AS [QTY ON ORDER]
> > from SC020230 As SC020230
> > JOIN SC020130 As SC020130
> > on SC020230.SFLINEITEM_I = SC020130.SFLINEITEM_I
> > JOIN MRPW4060 As MRPW4060
> > on SC020130.ITEMNMBR = MRPW4060.ITEMNMBR
> > where SC020230.PLANNAME_I = 'MRP FG1' and SC020130.ITEMNMBR = '89417' and
> > SOPTYPE = '2') As I
> > GROUP BY ITEMNMBR,
> > SFLINEITEM_I,
> > DATE1,
> > QTYTOFORECOST_I,
> > DUEDATE,
> > QUANTITY
> > ORDER BY ITEMNMBR ASC

>
>
>

  Réponse avec citation
Réponse


Outils de la discussion

Règles de messages
Vous ne pouvez pas créer de nouvelles discussions
Vous ne pouvez pas envoyer des réponses
Vous ne pouvez pas envoyer des pièces jointes
Vous ne pouvez pas modifier vos messages

Les balises BB sont activées : oui
Les smileys sont activés : oui
La balise [IMG] est activée : oui
Le code HTML peut être employé : non
Trackbacks are oui
Pingbacks are oui
Refbacks are oui


Fuseau horaire GMT +1. Il est actuellement 03h25.


Édité par : vBulletin® version 3.7.3
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.2.0 RC5 Tous droits réservés.
Version française #16 par l'association vBulletin francophone
PHWinfo est un site Éducation Sans Frontières ©2000-2008
Ad Management by RedTyger
©Tous droits réservés par les parties respectives
Page generated in 0,28553 seconds with 11 queries