Skip to main content
Inspiring
October 17, 2012
Answered

SQL builder SQL Statement

  • October 17, 2012
  • 1 reply
  • 1017 views

I see a web site source code that developers use SQL Builder to build about 300 queries against SQL Server, but it can be done by a stored procedure or group by clause in the SQL statement.

The performance of the web site looks OK,

I would like to know does ColdFusion run the SQL statment against server 300 times or it smart enough to know and convert it to run once against server once only.

Are there any performance impact from ColdFusion or SQL server side?

Your information and help is great appreciated,

Regards,

iccsi,

    This topic has been closed for replies.
    Correct answer BKBK

    iccsi wrote:

    My question is the 300 queries can be simplified as a simple SQL like

    Select MyName, count(MyID)  from myTable

    where myName =  'Name1'

    group by MyName

    Select MyName, count(MyID) from myTable

    where myName = 'Name2'

    group by MyName

    Select MyName, count(MyID) from myTable

    where myName = 'Name3'

    group by MyName

    can be some one use like following

    Select MyName, count(MyID) from myTable

    group by MyName

    or save as a stored procedure which the web server or web page only hit database server once instead of 300 times.

    I would like to know does ColdFusion is smart enough to know the SQL are similar and only run SQL once against dabase server.

    In my opinion, query-of-a-query is a smart enough solution to the problem. In the following example, ColdFusion visits the database just once!

    <cfquery name="mainQuery" datasource="myDSN">

    select MyName, count(MyID) from myTable

    group by MyName

    </cfquery>

    <cfquery dbType="query" name="subQuery1">

    select *

    from myQuery

    where myName =  'Name1'

    </cfquery>

    <cfquery dbType="query" name="subQuery2">

    select *

    from myQuery

    where myName =  'Name2'

    </cfquery>

    ...

    ...

    <cfquery dbType="query" name="subQuery300">

    select *

    from myQuery

    where myName =  'Name300'

    </cfquery>

    1 reply

    Inspiring
    October 17, 2012

    I don't understand your 1st sentence, particulary the part about being done by a stored procedure or group by clause.  These are very different things.

    iccsiAuthor
    Inspiring
    October 17, 2012

    Thanks for the message and help.

    Yes, 'Group by' clause and stored procedures are different things.

    My question is the 300 queries can be simplified as a simple SQL like

    Select MyName, count(MyID)  from myTable

    where myName =  'Name1'

    group by MyName

    Select MyName, count(MyID) from myTable

    where myName = 'Name2'

    group by MyName

    Select MyName, count(MyID) from myTable

    where myName = 'Name3'

    group by MyName

    can be some one use like following

    Select MyName, count(MyID) from myTable

    group by MyName

    or save as a stored procedure which the web server or web page only hit database server once instead of 300 times.

    I would like to know does ColdFusion is smart enough to know the SQL are similar and only run SQL once against dabase server.

    I tried to run the web site it seems there is no delay.

    Thanks again for helping,

    Regards,

    iccsi,

    Inspiring
    October 18, 2012

    ColdFusion is obedient, not smart.  It executes the code you give it.

    What it does do is keep database connections open for awhile which does increase efficiency somewhat.