tips54
asked on
cature date a column appear
I have a report that shows a lot of data for inventory. I would like to create a date that shows the first time a line item appear on the report. Is there a way do that?
i.e.
Item PO Status Date-first-appear-on-repor t
X 1234 urgent 2/7/13
the date field needs to be static it does not change every time the report runs.
i.e.
Item PO Status Date-first-appear-on-repor
X 1234 urgent 2/7/13
the date field needs to be static it does not change every time the report runs.
Use of the min aggregate requires a group by clause -
select item, po, status, min(date) as date_first_appear_on_repor t
from yourtable
group by item, po, status
Some sample data and your expected results would be helpful as Giannis suggests.
select item, po, status, min(date) as date_first_appear_on_repor
from yourtable
group by item, po, status
Some sample data and your expected results would be helpful as Giannis suggests.
Hi, it doesn'tneed a group by as it is a subquery and the min is the only output of it. You need a group by when you have a column which you don' t agregate on.
Giannis
Giannis
jyparask,
I apologize. I misread your comment and didn't see it as a sub-select. I'd still like to see some sample data and expected results, though. :-)
I apologize. I misread your comment and didn't see it as a sub-select. I'd still like to see some sample data and expected results, though. :-)
On that we agree. :)
>> a lot of data
if there is a lot of data; a correlated subquery within the selection list can be slow/expensive, an alternative is to place a subquery within the FROM such as this
if there is a lot of data; a correlated subquery within the selection list can be slow/expensive, an alternative is to place a subquery within the FROM such as this
SELECT
Item
, PO
, STATUS
, Date_First_Appear_On_Report
FROM tblItemReport EXTERNAL
INNER JOIN (
SELECT
Item
, MIN(DATE) AS Date_First_Appear_On_Report
GROUP BY Item
FROM tblItemReport
) Internal
ON EXTERNAL.Item = Internal.Item
but, as mentioned earlier, more information would help
ASKER
Thank you folks. I don't know if I can provide more data. I think the min date will work. One main issue with this is the Date is not any where in the table. I simply want to capture the date from a sql function. All the table has ItemX, PO , Status. For example I run a query to collect those 3 piece of information to render to SSRS. If a particular item appear on the report 3 days ago. The would look like this:
Item PO Status DateFirstAppear
x 123 Urgent 3/31/13
can this be done?
Item PO Status DateFirstAppear
x 123 Urgent 3/31/13
can this be done?
Can you post the code for the sql function that retrieves the date?
>>I think the min date will work.<<
min(date) can't work if there is no date. Perhaps something like "min(sql_function(paramete r)) as Date_First_Appear_On_Repor t" might though, which is why I would like to see the function code.
min(date) can't work if there is no date. Perhaps something like "min(sql_function(paramete
can this be done?
NO
>> One main issue with this is the Date is not any where in the table
>> I simply want to capture the date (and put it where?)
>> If a particular item appear on the report 3 days ago (will a stored procedure be used when the report is run?)
You cannot "recall" when an item appeared in a report - unless you store that information
Will you be storing "the date"?
NO
>> One main issue with this is the Date is not any where in the table
>> I simply want to capture the date (and put it where?)
>> If a particular item appear on the report 3 days ago (will a stored procedure be used when the report is run?)
You cannot "recall" when an item appeared in a report - unless you store that information
Will you be storing "the date"?
ASKER
Paul,
(and put it where?)
Put the data on a report.
Yes a store procedure will be used.
(and put it where?)
Put the data on a report.
Yes a store procedure will be used.
(put it where?) = where will you store the date?
if you are using a stored procedure,
you will know if an item is about to appear on the report...
and you can test also if it is has already appeared before, if you have a table for this...
if an item has not appeared before...
insert it into that table...
next time
you will know if an item is about to appear on the report...
and you can test also if it is has already appeared before, if you have a table for this...
if an item has not appeared before...
insert it into that table...
etc.
am I missing something? If you don't store the required information somewhere you simply will not be able to compute when an item first appeared on the report
if you are using a stored procedure,
you will know if an item is about to appear on the report...
and you can test also if it is has already appeared before, if you have a table for this...
if an item has not appeared before...
insert it into that table...
next time
you will know if an item is about to appear on the report...
and you can test also if it is has already appeared before, if you have a table for this...
if an item has not appeared before...
insert it into that table...
etc.
am I missing something? If you don't store the required information somewhere you simply will not be able to compute when an item first appeared on the report
ASKER
I ended cancelling this report as the data was only manipulated via a VIEW. The date the item appear on the report is not stored field in a table.
ASKER CERTIFIED SOLUTION
membership
Create a free account to see this answer
Signing up is free and takes 30 seconds. No credit card required.
ASKER
thanks.
Open in new window
If you give some schema and sample data we may be able to help further.
Giannis