SQL Server Performance

wrong results

Discussion in 'SQL Server 2005 General Developer Questions' started by pavlos vagionas, Sep 25, 2007.

  1. pavlos vagionas New Member

    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
  2. ndinakar Member

    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.
  3. pavlos vagionas New Member

    Thank you dinakar.
  4. satya Moderator

    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.
  5. pavlos vagionas New Member

    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,
    ... etc
    from @DataTable as DAT or either like select @p1 = DAT.field1,
    @p2 = DAT.field2,
    ... etc
    ( 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
    @p1 = tempDAT.field1, @p2 = tempDAT.field2, ... etc
    from @TempData as tempDAT
    end Is there any other simple solution ?
  6. ndinakar Member

    Normally I initialize all my numeric variables and set them to 0
    SELECT @param1 = 0, @param2 = 0, @param3 = 0 etc.

Share This Page