Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Create a View with every day of the month, programmatically in SQL

Posted on 2006-11-03
1
Medium Priority
?
840 Views
Last Modified: 2010-10-05
Experts,

I've got a table that shows Begin_Date, End_Date, Exchange_Rate.  The rate may change weekly.

I'd like to create a view that lists every day of the month, with the exchange rate shown for that day.

Can you think of a way, in using SQL code, I can SELECT every day of the month, and link it to my Exchange Rate table?
0
Comment
Question by:AptDev
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
1 Comment
 
LVL 10

Accepted Solution

by:
AaronAbend earned 2000 total points
ID: 17870191

declare @adate datetime
declare @monthno int
begin

set @adate='11/01/2006' - seed with a date
set @monthno = datepart(mm,@adate)

while (datepart(mm,@adate)=@monthno)
  begin
  select exchangerate from table1 where adate=@adate
  set @adate=dateadd(d, 1, @adate)

  end
end

0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Why is this different from all of the other step by step guides?  Because I make a living as a DBA and not as a writer and I lived through this experience. Defining the name: When I talk to people they say different names on this subject stuff l…
The Delta outage: 650 cancelled flights, more than 1200 delayed flights, thousands of frustrated customers, tens of millions of dollars in damages – plus untold reputational damage to one of the world’s most trusted airlines. All due to a catastroph…
Using examples as well as descriptions, and references to Books Online, show the documentation available for date manipulation functions and by using a select few of these functions, show how date based data can be manipulated with these functions.
Viewers will learn how the fundamental information of how to create a table.

722 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question