Queries slower with SQL Server than Access

Ask a Question related to Coldfusion Database Access, Design and Development.

  1. #1

    Default Queries slower with SQL Server than Access

    Hoping for better security and performance, I'm moving data from an Access
    database to SQL Server. However, our more query-intensive reports in CF are
    taking significantly longer to run with SQL Server, not what I expected. For
    example, the following query counts how many eligible surveys received a
    response of '2' to each of the survey questions. Here's the SQL version:
    select SourceID, count1_1 = sum (case when Q1_1=2 then 1 else 0 end), count1_2
    = sum (case when Q1_2=2 then 1 else 0 end), count1_3 = sum (case when Q1_3=2
    then 1 else 0 end), count1_4 = sum (case when Q1_4=2 then 1 else 0 end),
    count1_5 = sum (case when Q1_5=2 then 1 else 0 end), count1_6 = sum (case when
    Q1_6=2 then 1 else 0 end), count1_7 = sum (case when Q1_7=2 then 1 else 0 end),
    count1_8 = sum (case when Q1_8=2 then 1 else 0 end), count1_9 = sum (case when
    Q1_9=2 then 1 else 0 end), count2_1 = sum (case when Q2_1=2 then 1 else 0 end),
    count2_2 = sum (case when Q2_2=2 then 1 else 0 end), count2_3 = sum (case when
    Q2_3=2 then 1 else 0 end), count2_4 = sum (case when Q2_4=2 then 1 else 0 end),
    count2_5 = sum (case when Q2_5=2 then 1 else 0 end), count2_6 = sum (case when
    Q2_6=2 then 1 else 0 end), count3_1 = sum (case when Q3_1=2 then 1 else 0 end),
    count3_2 = sum (case when Q3_2=2 then 1 else 0 end), count3_3 = sum (case when
    Q3_3=2 then 1 else 0 end), count3_4 = sum (case when Q3_4=2 then 1 else 0 end),
    count4_1 = sum (case when Q4_1=2 and StudentAge > 2 and StudentAge < 7 then 1
    else 0 end), count4_2 = sum (case when Q4_2=2 and StudentAge > 4 and StudentAge
    < 9 then 1 else 0 end), count4_3 = sum (case when Q4_3=2 and StudentAge > 13
    then 1 else 0 end), count4_4 = sum (case when Q4_4=2 and StudentAge > 13 then 1
    else 0 end), count4_5 = sum (case when Q4_5=2 and StudentAge > 13 then 1 else 0
    end), count5_1 = sum (case when Q5_1=2 and StudentAge < 5 then 1 else 0 end),
    count5_2 = sum (case when Q5_2=2 and StudentAge < 5 then 1 else 0 end),
    count5_3 = sum (case when Q5_3=2 and StudentAge < 5 then 1 else 0 end),
    count5_4 = sum (case when Q5_4=2 and StudentAge < 5 then 1 else 0 end),
    count5_5 = sum (case when Q5_5=2 and StudentAge < 5 then 1 else 0 end),
    count5_6 = sum (case when Q5_6=2 and StudentAge < 5 then 1 else 0 end),
    count5_7 = sum (case when Q5_7=2 and StudentAge < 5 then 1 else 0 end),
    count6_1 = sum (case when Q6_1=2 then 1 else 0 end), count6_2 = sum (case when
    Q6_2=2 then 1 else 0 end), count6_3 = sum (case when Q6_3=2 then 1 else 0 end),
    count6_4 = sum (case when Q6_4=2 then 1 else 0 end), count6_5 = sum (case when
    Q6_5=2 then 1 else 0 end) from tblSurveys where districtID IN
    (20,21,22,23,24,25,26,27,28,29,30,31,32,33,34,35,3 6,38) group by SourceID order
    by SourceID CF debugging times this query at 250ms, whereas the Access query
    runs in 63ms. And, that's with nearly twice as many surveys recorded in the
    Access database. The Access query is essentially the same, using IIF instead of
    CASE (e.g. Sum(IIf(Q1_1=2,1,0)) as count1_1). When I run the SQL query in Query
    Analyzer, the results come back instantaneously (zero seconds), so the problem
    seems to be with ColdFusion's handling of the query. I tried using a stored
    procedure instead of a query and ColdFusion took just as long. Any suggestions
    for improving performance? Thanks!

    cfoster Guest

  2. Similar Questions and Discussions

    1. SQL queries when Access is open
      My Authorware training piece sends and retrieves data through asp pages that are connected to an Access database. Three asp pages use SQL SELECT,...
    2. Creating queries in Access (for ASP)
      Hi, So far I have been writing ASP and embedding my SQL in the ASP pages. But, I've heard advantages of creating queries inside the database...
    3. Translate Access queries to ASP
      Hi, I'm still confused about my queries, I want to do something is ASP that is easily done in Access. I'll post the Access queries below as a...
    4. using Access queries using ADOX
      Hello, I have the following code in an asp 3.0 page: Dim dbConn As adodb.Connection Dim cat As ADOX.Catalog Dim view As ADOX.view Set dbConn...
    5. SQL Server 2000 SP3: Why is Table variable slower than temp tables?
      Hello, Recently, I am trying to optimize some old stored procedures. In the process, I found out in the online help that a "table variable" is...
  3. #2

    Default Re: Queries slower with SQL Server than Access

    Maybe run it as either a view or stored procedure. Just taking a guess
    briguyCF151 Guest

  4. #3

    Default Re: Queries slower with SQL Server than Access

    Do you have indices on the aggregated and WHERE clause fields? Run the query
    in QA with Execution Plan tab turned on and see if there are table scans.
    Definitely create an SP so SQL can cache the plan.

    philh Guest

Posting Permissions

  • You may not post new threads
  • You may post replies
  • You may not post attachments
  • You may not edit your posts

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 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139