Skip to main content
Participant
August 18, 2011
Question

How do you query a SQL view

  • August 18, 2011
  • 3 replies
  • 772 views

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.

This topic has been closed for replies.

3 replies

broroboAuthor
Participant
August 18, 2011

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?

Owainnorth
Inspiring
August 18, 2011

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

Inspiring
August 18, 2011

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

Owainnorth
Inspiring
August 18, 2011

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".