Looping Issue With File Output

  • I'm converting a terribly written ColdFusion script and migrating it to T-SQL (SQL Server 2012). My problem is, I'm having issues with how to get these loops sorted out. For instaces, the CF query wouold be something like :

    <cfquery name = "getData" datasource = "db">

    SELECT id, name, date FROM table

    </cfquery>

    Following that, this query is looped into another set of queries:

    <cfloop query = "getData">

    <cfquery name = "getAddress" datasource = "globaladdress">

    select * from globalAddress

    where addressID = '#addressID#'

    </cfquery>

    <cfquery name = "getBilling" datasource = "datavault">

    select business, sub_business from businessTable

    where buc = '#buc#'

    </cfquery>

    </cfloop>

    What I'm looking to do is turn the first query "getData" into the above loop, but rather in T-SQL. I'm at a loss ATM and it's most likely just brain farts but any guidance would be much appreciated. Thanks a bunch!

    Danny Sheridan
    Comtekh, Inc.

  • PS - I understand the queries within the original loop do not match, it was a copy and paste effort from my original code to quicken things up 😀

    Danny Sheridan
    Comtekh, Inc.

  • Can you expand on this bit please?

    What I'm looking to do is turn the first query "getData" into the above loop, but rather in T-SQL.

    I don't know what turning a query into a loop means ...

    The absence of evidence is not evidence of absence
    - Martin Rees
    The absence of consumable DDL, sample data and desired results is, however, evidence of the absence of my response
    - Phil Parkin

  • May be better suited for developers with CF experience. I'm an SQL developer, not CF so had this project been given to me off the bat I would've had it working correctly from the get-go. Basically the main query is used as a loop to extract data from other tables/queries within that loop based on specific bits of information (i.e. main query has name but not address info - so the loop from the main query would bring in the address info if that makes any sense).

    Danny Sheridan
    Comtekh, Inc.

  • And PS....I know this is terrible database design...have to work with what I was given unfortunately.

    <MAIN QUERY>

    <cfquery name = "getData" datasource = "db">

    SELECT id, name, date FROM table

    </cfquery>

    <LOOP>

    <cfloop query = "getData">

    select a, b, c FROM table_2

    where id = id

    </cfloop>

    <END LOOP>

    Maybe this will help clarify

    Danny Sheridan
    Comtekh, Inc.

Viewing 5 posts - 1 through 4 (of 4 total)

You must be logged in to reply to this topic. Login to reply