Friday, March 30, 2012

Query Q

Hi,
In a table I've Cust_ID, Date_IN, Order_Num.
I'd like to list the Cust_ID who have not placed an order for the last 5
months.
HOWTO?
TIA
Ana
SQL2005, Acc03Try:
select *
from dbo.customer as c
where not exists (
select *
from dbo.order as oh
where oh.cust_id = c.cust_id
and oh.date_in >= convert(varchar(6), dateadd(month, -4, getdate()), 112) +
'01'
)
go
AMB
"AnaT" wrote:
> Hi,
> In a table I've Cust_ID, Date_IN, Order_Num.
> I'd like to list the Cust_ID who have not placed an order for the last 5
> months.
> HOWTO?
> TIA
> Ana
>
> SQL2005, Acc03
>|||On Jun 26, 10:19 pm, "AnaT" <ananos...@.yahoo.es> wrote:
> Hi,
> In a table I've Cust_ID, Date_IN, Order_Num.
> I'd like to list the Cust_ID who have not placed an order for the last 5
> months.
> HOWTO?
> TIA
> Ana
> SQL2005, Acc03
Hi, try something like followig:
select cust_id
from some_table
group by cust_id
having datediff(month,max(date_in),getdate()) >= 5
HTHsql

No comments:

Post a Comment