4 Replies Latest reply on Aug 18, 2011 12:16 PM by Owain North

    How do you query a SQL view

    brorobo

      Is it possible to query a MS SQL 2005 view directly from a web page instead of querying tables in a database?

       

      Here is our server settings: ColdFusion MX
      Version  7,0,2,142559
      Edition  Enterprise (DevNet)
      Operating System  Windows 2003
      OS Version  5.2

      The view is in the same database as the original tables.

       

      If it is possible to do, how would one go about doing it?

       

      Thanks in advance for your assistance.

        • 1. Re: How do you query a SQL view
          Owain North Level 4

          Perhaps I misunderstand, but views are queried in exactly the same way tables are.

           

          Explain "directly from a web page instead of querying tables in a database".

          1 person found this helpful
          • 2. Re: How do you query a SQL view
            -==cfSearching==- Level 4

            A "view" is just a virtual table. So querying a "view" is no different than querying a physical table.

            1 person found this helpful
            • 3. Re: How do you query a SQL view
              brorobo Level 1

              My apologies, but I'm not very good on the database end of my knowledge base.

               

              Basically, our database administrator set up a view for us that collects a lot of information from various tables. I need to output that information to a web page.

               

              But the thing is, I may need to output it to multiple pages, and I didn't want to reproduce the query on multiple pages, just in case the view needs to change at some point in the future. So, I thought I would query the view. Kind of like using a cfinclude. Speaking of, I guess I can always put the actual query in a cfinclude file and call it where ever I need it, but I thought if I could query the view directly, it would save me a step.

               

              Does that help?

              • 4. Re: How do you query a SQL view
                Owain North Level 4

                So you're saying you want a query, stored someone centrally, which retrieves the data from a view. You will then use this in a few places on your site?

                 

                If so, you simply want to wrap the CFQUERY up in a CFFUNCTION inside a Component (.cfc file). Have a big of a Google about on those, you'll find countless resources which can explain it better than I can