Question : SQL datetime issue: The following 2 sections of code produce different results.

I'm trying to replace the existing query 1 because it is extremely slow, however both produce different results?

QUERY 1
Set @StartDate = '08/25/2006 12:45 PM'      --Start date time
Set @EndDate = '08/27/2006 11:17 PM'                            --End date time
Where convert (char(11), DateOfBusiness, 101) +
      cast(cast([Hour] as char(2)) + ':' +
      cast([Minute] as char(2)) as datetime)
       between @StartDate and
      @EndDate
*********************************************
QUERY 2:
--Set @StartDate = '2006-08-25 12:45:00'      --Start date time
--Set @EndDate = '2006-08-27 23:17:00'      --End date time
Where DateOfBusiness between @StartDate and @EndDate

Answer : SQL datetime issue: The following 2 sections of code produce different results.

Oh, the update thing was just a one time operation to move so you stop using the hour and minutes column and put everything in the Dateofbusiness one. But since you mention that this database is from a vendor I guess you cannot modify it, so I would try this approach then (I've created an additional temp table with an extra column which will include date and time):

1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
38:
39:
40:
41:
42:
43:
44:
45:
46:
47:
48:
49:
50:
51:
52:
53:
/*----------------------------------------
Use to determine the number of pints sold
by keg by store for a period of time.
Change the Aloha Store ID, InStore ID, 
Ingredent, Start and End Times
------------------------------------------
*/


Use RUDY

Declare @Ingred Char(19)
Declare @InStoreID Char(5)
Declare @AlohaID Char(10)
Declare @StartDate DateTime 
Declare @EndDate DateTime

set @InStoreID = '00200'            --Instore ID
set @AlohaID ='6483'                  --Aloah ID
set @Ingred = 'kb dos xx'            --InStore Item Code
Set @StartDate = '08/25/2006 12:45 PM'      --Start date time
Set @EndDate = '08/27/2006 11:17 PM'      --End date time


select PLUNumber, IngredQty 
Into #temp_Beer
from arm01011
Where Ingredient = @Ingred
      and StoreID = @InStoreID

Use ALOHA_POS

select 	*, 
	DateofBusiness1 = cast(convert (char(11), DateOfBusiness, 101) + ' ' + cast([Hour] as char(2)) + ':' +  cast([Minute] as char(2)) as datetime) 
into #temp1
from repman.dpvHstGndItem
where 	FKStoreId = @AlohaID and 
	FKItemId in (Select PLUNumber From #temp_Beer)


select FKItemId, Count(FKItemId) as UnitsSold
Into #temp_UnitsSold
from #temp1
where DateofBusiness1 @StartDate and @EndDate 
Group by FKItemId

Select Sum(b.IngredQty * u.UnitsSold)/15 as PintsSold
From #temp_Beer b inner join #temp_UnitsSold u
      on b.PLUNumber = u.FKItemId

Drop Table #temp_Beer
Drop table #temp_UnitsSold
drop table #temp1
Random Solutions  
 
programming4us programming4us