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.
| Author |
Topic |
|
kamal.A
Yak Posting Veteran
70 Posts |
Posted - 2008-05-13 : 15:09:29
|
| Hi All,I need to display the rent not paid months in the year. How can I form the query?Help me.Kamal. |
|
|
tkizer
Almighty SQL Goddess
38200 Posts |
Posted - 2008-05-13 : 15:11:30
|
| http://weblogs.sqlteam.com/jeffs/archive/2008/05/13/question-needed-not-answer.aspxTara KizerMicrosoft MVP for Windows Server System - SQL Serverhttp://weblogs.sqlteam.com/tarad/Database maintenance routines:http://weblogs.sqlteam.com/tarad/archive/2004/07/02/1705.aspx |
 |
|
|
kamal.A
Yak Posting Veteran
70 Posts |
Posted - 2008-05-13 : 15:19:52
|
| Sorry,I have a table RentMaster the fields areId Month Year Rent1 Jan 2007 25002 Feb 2007 25003 Mar 2007 25004 Apr 2007 25005 May 2007 25006 Jun 2007 25007 Jul 2007 2500 In year 2007 the rent arrears months are Aug,Sep,Oct,Nov and Dec.My requirement is, to get the rent arrears month from the above table.Kindly help me.Kamal, |
 |
|
|
SwePeso
Patron Saint of Lost Yaks
30421 Posts |
Posted - 2008-05-13 : 15:45:27
|
And where do you store the payments? E 12°55'05.25"N 56°04'39.16" |
 |
|
|
kamal.A
Yak Posting Veteran
70 Posts |
Posted - 2008-05-13 : 16:15:52
|
| I need to display only arrears months. |
 |
|
|
SwePeso
Patron Saint of Lost Yaks
30421 Posts |
Posted - 2008-05-13 : 16:32:05
|
[code]DECLARE @Sample TABLE (ID INT, Month CHAR(3), Year SMALLINT, Rent INT)INSERT @SampleSELECT 1, 'Jan', 2007, 2500 UNION ALLSELECT 2, 'Feb', 2007, 2500 UNION ALLSELECT 3, 'Mar', 2007, 2500 UNION ALLSELECT 4, 'Apr', 2007, 2500 UNION ALLSELECT 5, 'May', 2007, 2500 UNION ALLSELECT 6, 'Jun', 2007, 2500 UNION ALLSELECT 7, 'Jul', 2007, 2500SELECT v.theMonth, 2007FROM ( SELECT CONVERT(CHAR(3), DATEADD(MONTH, Number, '19000101'), 107) AS theMonth FROM master..spt_values WHERE Type = 'p' AND Number < 12 ) AS vLEFT JOIN @Sample AS s ON s.Month = v.theMonth AND s.Year = 2007WHERE s.ID IS NULL[/code] E 12°55'05.25"N 56°04'39.16" |
 |
|
|
R.Prabu
Starting Member
33 Posts |
Posted - 2008-07-01 : 18:42:35
|
| I am aslo Having the Month Table in the above query how to form the queryhelp meRegards,Prabu R |
 |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2008-07-02 : 00:52:37
|
quote: Originally posted by R.Prabu I am aslo Having the Month Table in the above query how to form the queryhelp meRegards,Prabu R
Replace the first derived table by your month table in the query given above. |
 |
|
|
|
|
|
|
|