ptheriault
IS-IT--Management
Without running it.
What do you think this will return..
- Paul
- If at first you don't succeed, find out if the loser gets anything.
What do you think this will return..
Code:
[COLOR=green]-- Prepare sample data
[/color][COLOR=blue]DECLARE[/color] @Dates [COLOR=blue]TABLE[/color] (StartingDate [COLOR=#FF00FF]DATETIME[/color], EndingDate [COLOR=#FF00FF]DATETIME[/color])
[COLOR=blue]INSERT[/color] @Dates
[COLOR=blue]SELECT[/color] [COLOR=red]'20010101'[/color], [COLOR=red]'20070204'[/color] UNION ALL
[COLOR=blue]SELECT[/color] [COLOR=red]'20071231'[/color], [COLOR=red]'20080101'[/color] UNION ALL
[COLOR=blue]SELECT[/color] [COLOR=red]'20070318'[/color], [COLOR=red]'20080101'[/color]
[COLOR=green]-- Show the expected output
[/color]
[COLOR=blue]SELECT[/color] StartingDate,
EndingDate,
[COLOR=#FF00FF]DATEDIFF[/color]([COLOR=#FF00FF]MONTH[/color], StartingDate, EndingDate) [COLOR=blue]AS[/color] [[COLOR=#FF00FF]Month[/color] [COLOR=#FF00FF]DatePart[/color]],
[COLOR=#FF00FF]DATEDIFF[/color]([COLOR=#FF00FF]YEAR[/color], StartingDate, EndingDate) [COLOR=blue]AS[/color] [[COLOR=#FF00FF]Year[/color] [COLOR=#FF00FF]DatePart[/color]]
[COLOR=blue]FROM[/color] @Dates
[COLOR=blue]ORDER[/color] [COLOR=blue]BY[/color] StartingDate
- Paul

- If at first you don't succeed, find out if the loser gets anything.