Skip to Content
author's profile photo Former Member
Former Member

Qry for 1st order

Hi there,

it seems there is a blockhead. I'd like to write a query which lists all customer with first orders in a given date range. The logic is clear to me, but i do not find the solution. I would be pleased for help.

Thanks.

Add a comment
10|10000 characters needed characters exceeded

Assigned Tags

Related questions

2 Answers

  • author's profile photo Former Member
    Former Member
    Posted on Nov 12, 2008 at 12:04 PM

    Hi,

    You can try--

    select Cardcode from ORDR where DocDate between fromdate and todate group by Cardcode

    Add a comment
    10|10000 characters needed characters exceeded

  • Posted on Nov 12, 2008 at 12:31 PM

    To get the customers, who's first sales order arrived in a time interval, try this query:

    declare @d1 datetime
    declare @d2 datetime
    /*SELECT top 1 T0.[DocDate] FROM ORDR T0
     WHERE T0.[DocDate] between '[%0]' and '[%1]'*/
    set @d1='[%0]' 
    set @d2='[%1]' 
    Select A.Cust,A.Min_Date From 
    (SELECT min( T0.[DocDate])'Min_date', T0.[CardCode]'Cust'
     FROM ORDR T0
     GROUP BY T0.[CardCode] ) A
    Where A.Min_Date between @d1 and  @d2

    Add a comment
    10|10000 characters needed characters exceeded

Before answering

You should only submit an answer when you are proposing a solution to the poster's problem. If you want the poster to clarify the question or provide more information, please leave a comment instead, requesting additional details. When answering, please include specifics, such as step-by-step instructions, context for the solution, and links to useful resources. Also, please make sure that you answer complies with our Rules of Engagement.
You must be Logged in to submit an answer.

Up to 10 attachments (including images) can be used with a maximum of 1.0 MB each and 10.5 MB total.