Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 Date Help

Author  Topic 

l_schneider
Starting Member

4 Posts

Posted - 2010-06-15 : 12:42:02
I am writing a query that needs to have a start date. I do not know how to do this.

My query needs to be of any local customers that have not order since "mm/dd/yyyy"

webfred
Master Smack Fu Yak Hacker

8781 Posts

Posted - 2010-06-15 : 13:01:26
select *
from customer c
where not exists(select * from orders o where o.custId=c.custId and o.orderdate > 'yyyymmdd')


No, you're never too old to Yak'n'Roll if you're too young to die.
Go to Top of Page

l_schneider
Starting Member

4 Posts

Posted - 2010-06-15 : 13:20:03
Sorry my first question wasn't very specific..
Here's what I have so far..
DECLARE @CALENDAR DateTime
SET @CALENDAR = '{{{Select Start Date}}}'
SELECT
tblCustomer.CustID as 'Customer ID',
tblCustomer.LocalName as 'Local Name',
tblCustomer.LocalContact as 'Local Contact',
tblCustomer.LocalAddress as 'Local Address',
tblCustomer.LocalCity as 'Local City',
tblCustomer.LocalState as "Local State',
tblCustomer.LocalZip as 'Local Zip'

FROM
tblCustomer
INNER JOIN tblOrder ON tblCustomer.CustID = tblOrder.CustID

(this is where I have the problem)

WHERE
tblOrder.OrderDate?????
AND tblCustomer.BusinessID = 1
AND tblCustomer.HouseAccount = 'FALSE'

GROUP BY
tblCustomer.CustID,
tblCustomer.LocalName,
tblCustomer.LocalContact,
tblCustomer.LocalAddress,
tblCustomer.LocalCity
tblCustomer.LocalState
tblCustomer.LocalZip

ORDER BY
tblCustomer.CustID,
tblCustomer.LocalName,
tblCustomer.LocalContact,
tblCustomer.LocalAddress,
tblCustomer.LocalCity
tblCustomer.LocalState
tblCustomer.LocalZip
Go to Top of Page

vijayisonly
Master Smack Fu Yak Hacker

1836 Posts

Posted - 2010-06-15 : 13:25:56
[code]SELECT
tblCustomer.CustID as 'Customer ID',
tblCustomer.LocalName as 'Local Name',
tblCustomer.LocalContact as 'Local Contact',
tblCustomer.LocalAddress as 'Local Address',
tblCustomer.LocalCity as 'Local City',
tblCustomer.LocalState as 'Local State',
tblCustomer.LocalZip as 'Local Zip'
FROM
tblCustomer
LEFT JOIN tblOrder ON tblCustomer.CustID = tblOrder.CustID AND tblOrder.OrderDate > 'yyyymmdd'
WHERE
tblOrder.CustID IS NULL
AND tblCustomer.BusinessID = 1
AND tblCustomer.HouseAccount = 'FALSE'
GROUP BY
tblCustomer.CustID,
tblCustomer.LocalName,
tblCustomer.LocalContact,
tblCustomer.LocalAddress,
tblCustomer.LocalCity
tblCustomer.LocalState
tblCustomer.LocalZip
ORDER BY
tblCustomer.CustID,
tblCustomer.LocalName,
tblCustomer.LocalContact,
tblCustomer.LocalAddress,
tblCustomer.LocalCity
tblCustomer.LocalState
tblCustomer.LocalZip[/code]
Go to Top of Page

l_schneider
Starting Member

4 Posts

Posted - 2010-06-15 : 13:32:23
Thank you so so much. :)
Go to Top of Page

vijayisonly
Master Smack Fu Yak Hacker

1836 Posts

Posted - 2010-06-15 : 13:37:22
Np. You are welcome.
Go to Top of Page

l_schneider
Starting Member

4 Posts

Posted - 2010-06-15 : 13:39:23
I'm sure I'll have more questions. I got handed a book yesterday and was told to make a query by end of day TODAY. I tried to learn quickly. Lol. :)
Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2010-06-16 : 02:43:55
Also make sure to read this to know more about using proper DATE formats
http://beyondrelational.com/blogs/madhivanan/archive/2010/06/03/understanding-datetime-column-part-ii.aspx

Madhivanan

Failing to plan is Planning to fail
Go to Top of Page
   

- Advertisement -