SQL Server Forums
Profile | Register | Active Topics | Members | Search | Forum FAQ
 
Register Now and get your question answered!
Username:
Password:
Save Password
Forgot your Password?

 All Forums
 SQL Server 2008 Forums
 Transact-SQL (2008)
 Last day of the month
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

kwacz23
Starting Member

44 Posts

Posted - 03/09/2014 :  05:57:22  Show Profile  Reply with Quote
Hi

I would like to find all orders which finish in the last day of the month

select orderid,orderdate,custid,empid from Sales.Orders
where convert (date,orderdate,120) in (convert(date,(SELECT DATEADD(s,-1,DATEADD(mm, DATEDIFF(m,0,Sales.Orders.orderdate)+1,0)) from Sales.Orders),120))

Unfortunately this query return error message:

Subquery returned more than 1 value. This is not permitted when the subquery follows =, !=, <, <= , >, >= or when the subquery is used as an expression.

Pls help

k_a_f_k_a
Starting Member

Belgium
2 Posts

Posted - 03/09/2014 :  06:37:51  Show Profile  Reply with Quote
I think the error message is quite clear: The subquery is returning more than 1 row, which is then being passed as an expression towards convert().

Also, this looks needlessly complex. I guess this should work:
select orderid,orderdate,custid,empid from Sales.Orders
where datepart(day, dateadd(day, 1, orderdate)) = 1
Basically, add 1 day and check if this is the first day of any month.
Go to Top of Page
  Previous Topic Topic Next Topic  
 New Topic  Reply to Topic
 Printer Friendly
Jump To:
SQL Server Forums © 2000-2009 SQLTeam Publishing, LLC Go To Top Of Page
This page was generated in 0.05 seconds. Powered By: Snitz Forums 2000