Please start any new threads on our new
site at https://forums.sqlteam.com. We've got lots of great SQL Server
experts to answer whatever question you can come up with.
| Author |
Topic |
|
sica
Posting Yak Master
143 Posts |
Posted - 2001-05-15 : 13:38:46
|
| Hi,I have this query that it gave me headache all day.The problem is when I run this query the result varies as if I have a random value in the query.The first thing that I check was if there was activity in the db , if someone updated the tables.But nothing...When a took away the last three inner join I get the same result without variations.My question is why the variation result appears if none update the involved tables? Here it comes the query:SELECT DISTINCT Customer2.Customerid, Invoice_TelespecificationRow.Sunscribernbr, COUNT(DISTINCT(Invoice_TelespecificationRow.StartTime)), -- Nbr of calls ((SUM(CONVERT(INT,(SUBSTRING(langd,1,2)))) * 3600) + (SUM(CONVERT(INT,(SUBSTRING(langd,4,2)))) * 60) +(SUM(CONVERT(INT,(SUBSTRING(langd,7,2)))))) -- Nbr of sek FROM Customer2LEFT JOIN Invoice on Invoice.CustomerID = Customer2.CustomerID LEFT JOIN Invoice_TelespecificationRow on Invoice.InvoiceNbr = Invoice_TelespecificationRow.InvoiceNbrINNER JOIN Platform ON Customer2.Customerid = Platform.Customerid INNER JOIN CustomerProduct ON Platform.anlid = CustomerProduct.anlid INNER JOIN Tele on CustomerProduct.CustomerProductid = Tele.CustomerProductid WHERE (NOT (SUBSTRING(Invoice_TelespecificationRow.StartTime,1,2) >= '08' AND SUBSTRING(Invoice_TelespecificationRow.StartTime,1,2) < '18') OR DATENAME(WEEKDAY, Invoice_TelespecificationRow.Datum) IN ('Saturday', 'Sunday')) -- or Sat/Sun AND Invoice_TelespecificationRow.CalledNbr not like '0%' -- International does not start with 0!! AND Invoice.InvoiceDatum between '2000-11-01' and '2001-05-01'-- oct-mars AND REPLACE(Tele.SunscriberNr, '-', '')= Invoice_TelespecificationRow.Sunscribernbr GROUP BY Customer2.Customerid, Invoice_TelespecificationRow.Sunscribernbr |
|
|
|
|
|
|
|