Solved

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

Posted on 2006-11-03
1
832 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
1 Comment
 
LVL 10

Accepted Solution

by:
AaronAbend earned 500 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

What is SQL Server and how does it work?

The purpose of this paper is to provide you background on SQL Server. It’s your self-study guide for learning fundamentals. It includes both the history of SQL and its technical basics. Concepts and definitions will form the solid foundation of your future DBA expertise.

Join & Write a Comment

Introduced in Microsoft SQL Server 2005, the Copy Database Wizard (http://msdn.microsoft.com/en-us/library/ms188664.aspx) is useful in copying databases and associated objects between SQL instances; therefore, it is a good migration and upgrade tool…
Let's review the features of new SQL Server 2012 (Denali CTP3). It listed as below: PERCENT_RANK(): PERCENT_RANK() function will returns the percentage value of rank of the values among its group. PERCENT_RANK() function value always in be…
This video shows, step by step, how to configure Oracle Heterogeneous Services via the Generic Gateway Agent in order to make a connection from an Oracle session and access a remote SQL Server database table.
Viewers will learn how to use the UPDATE and DELETE statements to change or remove existing data from their tables. Make a table: Update a specific column given a specific row using the UPDATE statement: Remove a set of values using the DELETE s…

743 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

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now