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

Our new SQL Server Forums are live! Come on over! We've restricted the ability to create new threads on these forums.

SQL Server Forums
Profile | 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)
 Please help with the query
 Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

hromagda
Starting Member

1 Posts

Posted - 08/12/2013 :  09:39:15  Show Profile  Reply with Quote
Hello all
I would like to get one condition into my query.
I need to return numbers of contracts - in our db named[U_KELAR_CSML] from the table [@BOY_ABON] where... and now the requested condition...on contracts there are field 'date of activation' - U_BOY_FROM and 12 checkboxes for particular months(U_BOY_Jan; U_BOY_Feb, U_BOY-Mar,...), where you can tick how are invoices paid (monthly, quartely, once a half an year or once a year)and I need to get condition for all contracts paid once a half an year and more - difference between U_BOY_FROM and way of invoice paying is bigger than half an year. Could you help me with this condition?
Thank you

MuMu88
Aged Yak Warrior

549 Posts

Posted - 08/12/2013 :  11:20:01  Show Profile  Reply with Quote
Something like this:


DECLARE  @BOY_ABON TABLE (AccNo INT, U_BOY_Jan INT, U_BOY_Feb INT, U_BOY_Mar INT, U_BOY_Apr INT, U_BOY_May INT);

INSERT INTO @BOY_ABON
SELECT 1, 0,0,0,0,0
UNION 
SELECT 2, 1,0,0,0,0
UNION 
SELECT 3, 1,1,0,0,0
UNION 
SELECT 4, 1,1,1,0,0
UNION 
SELECT 5, 1,1,1,1,0
UNION 
SELECT 6, 1,1,1,1,1;

SELECT AccNo, (U_BOY_Jan + U_BOY_Feb +  U_BOY_Mar  +  U_BOY_Apr  +  U_BOY_May) as NumPayments FROM @BOY_ABON 
		WHERE (U_BOY_Jan + U_BOY_Feb +  U_BOY_Mar  +  U_BOY_Apr  +  U_BOY_May) > 2;



Go to Top of Page
  Previous Topic Topic Next 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.02 seconds. Powered By: Snitz Forums 2000