Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

SQL Command for creating a Query 2

Status
Not open for further replies.

thegad

Technical User
Jan 8, 2004
6
DE
Hi,

As the SQL command "CREATE TABLE" allows creating a new table, I'm looking for the same kind of SQL command for creating an Access Query.

Thanks for your help,

Gad.
 
Hi Gad,

I have used
Code:
CREATE VIEW view1 as SELECT * FROM table1
but as I remember it doesn't appear in the QUERIES window in ACCESS. I was able to use it in my program though.
 
A QUery that creates a query? Are you sure you really need to do it that way?
If this helps you: You can always implement a sub query:

SELECT * FROM (SELECT whatever FROM WHEREEVER...)

Is that what you need?

MakeItSo

Andreas Galambos
EDP / Technical Support Specialist
(andreas.galambos@bowneglobal.de)
HP:
 
I think nicsin is right. Access allows you to create a query that you can then use like a table in another query. This is normally called a view in relational databases - and the on-line documentation says CREATE VIEW is valid but only for Jet databases.

 
-10.gif

Aha! Didn't know that. Thanks nicsin and BNPMike.
 
Thanks for the help.

I was already trying the CREATE VIEW before but indeed it does not create a QUERY in Access. Nicsin had the good idea to try if the view is hidden somewhere. Apparently, it is the case, so thank you. Good idea!

But... (there is always a but)

I try the command : CREATE VIEW view1 as SELECT * FROM table1 ORDER BY var1. And surprise! I get the following error message : "Only simple SELECT queries are allowed in VIEWS". Argh...

So. HELP!

Gad.
 
Indeed the case. Now we come to the question: How are you going to use this view? The simplest answer to your question would be to ommit the
Code:
order by
clause from the
Code:
select
and use it when calling the view.
Code:
select * from view1 order by var1
 
For the order stuff, you right, but I have much more complex queries with plenty of LEFT JOIN. By removing the ORDER BY in these complex queries and creating them, I don't get any error message. So we can suppose that the others commands are accepted. Nevertheless, my calling software is not very happy because of the false ordering. Hence, i can't verify (nor in Access nor in my software as it is) if the VIEW is OK. Tomorrow (I'm living in Europe), I will modify my soft to put the order in, but it will surely cost run time.

Anyway, thanks to all, especially nicsin who was very helpfull.
 
Good luck and have a safe journey!

PS I don't know where you are but make sure you bring some warm clothes...;-)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top