Click here to Skip to main content
15,893,622 members
Home / Discussions / Database
   

Database

 
AnswerRe: How can i select all dates between date range? Pin
bobrien10015-Jun-12 8:11
bobrien10015-Jun-12 8:11 
You could accomplish this with a script rather than a single query. I have not run this and if you are allergic to table vars then stop reading. Presuming you have a begin date that is less than or equal to the end date you can proceed like this...

SQL
declare @loopDate as datetime
declare @dateRange as table ( aDate datetime )

set @loopDate = @beginDate
insert into @dateRange (aDate) values (@loopDate )  -- beginning of your date range

while @loopDate < @endDate 
begin
  Dateadd(day, @loopDate, 1)
  insert into @dateRange (aDate) values (@loopDate )
end

select aDate, isnull(quantity, 0)
from 
yourTable a
left outer join @dateRange b on
  b.aDate = a.Productiondate

I have not tested this. There might be a syntax flaw. Flame away. - Bill O'Brien
GeneralRe: How can i select all dates between date range? Pin
Corporal Agarn15-Jun-12 8:44
professionalCorporal Agarn15-Jun-12 8:44 
AnswerRe: How can i select all dates between date range? Pin
Mycroft Holmes15-Jun-12 13:44
professionalMycroft Holmes15-Jun-12 13:44 
AnswerRe: How can i select all dates between date range? Pin
Jörgen Andersson15-Jun-12 22:36
professionalJörgen Andersson15-Jun-12 22:36 
AnswerRe: How can i select all dates between date range? Pin
vvashishta18-Jun-12 20:09
vvashishta18-Jun-12 20:09 
Questionhow to make a duplicate database with new name in SQL Server 2008 Pin
nvarunkumar15-Jun-12 0:06
nvarunkumar15-Jun-12 0:06 
AnswerRe: how to make a duplicate database with new name in SQL Server 2008 Pin
Sandeep Mewara15-Jun-12 1:11
mveSandeep Mewara15-Jun-12 1:11 
GeneralRe: how to make a duplicate database with new name in SQL Server 2008 Pin
nvarunkumar15-Jun-12 2:04
nvarunkumar15-Jun-12 2:04 
GeneralRe: how to make a duplicate database with new name in SQL Server 2008 Pin
nvarunkumar18-Jun-12 21:59
nvarunkumar18-Jun-12 21:59 
AnswerRe: how to make a duplicate database with new name in SQL Server 2008 Pin
Paul Conrad19-Jun-12 8:22
professionalPaul Conrad19-Jun-12 8:22 
GeneralRe: how to make a duplicate database with new name in SQL Server 2008 Pin
nvarunkumar19-Jun-12 21:31
nvarunkumar19-Jun-12 21:31 
QuestionIn SQL Server, how to generate table script as a single statement? Pin
dexterama14-Jun-12 3:24
professionaldexterama14-Jun-12 3:24 
AnswerRe: In SQL Server, how to generate table script as a single statement? Pin
PIEBALDconsult14-Jun-12 4:09
mvePIEBALDconsult14-Jun-12 4:09 
GeneralRe: In SQL Server, how to generate table script as a single statement? Pin
dexterama14-Jun-12 5:50
professionaldexterama14-Jun-12 5:50 
AnswerRe: In SQL Server, how to generate table script as a single statement? Pin
Mycroft Holmes15-Jun-12 13:38
professionalMycroft Holmes15-Jun-12 13:38 
Questioni want to do left join that should not return same multiple rows Pin
asifkhan114-Jun-12 1:45
asifkhan114-Jun-12 1:45 
AnswerRe: i want to do left join that should not return same multiple rows Pin
DRKARTHIKRAJ14-Jun-12 2:32
DRKARTHIKRAJ14-Jun-12 2:32 
AnswerRe: i want to do left join that should not return same multiple rows Pin
asifkhan114-Jun-12 3:09
asifkhan114-Jun-12 3:09 
GeneralRe: i want to do left join that should not return same multiple rows Pin
DRKARTHIKRAJ15-Jun-12 1:53
DRKARTHIKRAJ15-Jun-12 1:53 
AnswerRe: i want to do left join that should not return same multiple rows Pin
Eddy Vluggen14-Jun-12 2:39
professionalEddy Vluggen14-Jun-12 2:39 
AnswerRe: i want to do left join that should not return same multiple rows Pin
Nolan Sunico14-Jun-12 5:03
Nolan Sunico14-Jun-12 5:03 
AnswerRe: i want to do left join that should not return same multiple rows Pin
Michael Potter15-Jun-12 10:43
Michael Potter15-Jun-12 10:43 
QuestionFinding "Missing" ID Numbers in Table (SQL Server 2005) Pin
Peter Bamuhigire13-Jun-12 7:25
Peter Bamuhigire13-Jun-12 7:25 
AnswerRe: Finding "Missing" ID Numbers in Table (SQL Server 2005) Pin
Mycroft Holmes13-Jun-12 14:45
professionalMycroft Holmes13-Jun-12 14:45 
AnswerRe: Finding "Missing" ID Numbers in Table (SQL Server 2005) Pin
Eddy Vluggen14-Jun-12 0:59
professionalEddy Vluggen14-Jun-12 0:59 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.