I have got wrong results from query that works normally for a year. i Checked data for each table involved into query joins and they are ok. Is it possible to be caused by corrupted indexes ? Does DBCC DBREINDEX solve the problem ? Is there anybody to ? Thank you in advanced
No. Indexes can speed up/slow down data retrieval but cannot alter the data being retrieved. you need to debug the proc or the query manually.
On the other hand for maintenance purpose you can still continue with DBCC DBREINEX and CHECKDB in order to tackle the fragmentation and check for any inconsistency of data in this case.
Hi, Thank you all for your help. I ' d like to share my expirience about this problem and maybe learn more about ... Finally the problem was caused by the query, as all of you proposedI noticed that queries like select @p1 = DAT.field1, @p2 = DAT.field2, ... etcfrom @DataTable as DAT or either like select @p1 = DAT.field1, @p2 = DAT.field2, ... etcfrom ( select Field1,field2, etcfrom P_TABLE ) as DAT when DAT does not fecth any row, then parameters can take any strange value !! (Is this normal ??)I tried the following solution : declare @Rowcount [int] insert into @TempDataselect Field1,field2, etc from P_TABLEselect @Rowcount=count(field1) from @TempData if @Rowcount = 0 begin set @p1 = 0 set @p2 = 0 ... etc end else begin select @p1 = tempDAT.field1, @p2 = tempDAT.field2, ... etc from @TempData as tempDATend Is there any other simple solution ?
Normally I initialize all my numeric variables and set them to 0 SELECT @param1 = 0, @param2 = 0, @param3 = 0 etc.