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 Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

newbie question about views

Status
Not open for further replies.

lifesupport

Programmer
May 18, 2004
64
US
I'd like to know if this is possible and if so how do I write the code?

I created a view in SQL and named it @view_selstate because I wanted the name to be a variable. I'm not sure if I can do this, but it took in SQL.

I then was trying to reference it in Visual Studio VB Script
i.e. if @view_selstate.selection = " " then

Selection is the field name

I'm getting the following error: BC30201: Expression expected.
I'm not even sure if this can be done

Thanks in advance
 
You can call the view pretty much anything you want. I don't know that I would use the @ symbol.

But you would access it the same as any SQL server ODBC table.

There are lots of sql odbc examples in this forum and on the web.

Simi
 
If I want the name of the view to actually be a variable, then I need to use the '@' symbol unless there is another way to do this. Since this results of this view will be used for the duration of the application, I don't want users overwriting each other's views so I want a dynamic view name based on the users session ID.
 
Guess I am confuesed. You are creating a dynamic view?

What is the content of the view? A view in most cases would be static and anybody could use and reuse it.

If it is dynamic you probably just need to use a query.

Also, I could see you naming the view based on the contents of a variable but why would you need to name it the actual name of the viariable and how would you generate the name so that the next person might over write it.

Please give some examples.

Simi

 
There may be different understandings to the statement.

[1] If the static views (or even tables or columns) have names actually not beginning with @ (normal case), and that you want to query with dynamic name identifier in an sql, then it is conceivable their names are passed around in some variables which begin with @. However, be always prepared to use prepared-statement/EXEC/EXECUTE type of operations to be successful.

[2] If one tragically desires to use names beginning with @ for them, surrounding them by back-ticks at _all_ time is still viable otherwise it would alreay be syntax error at (view's) creation time. But one has to ask: why! do such a thing indeed.
 
In fact, the real question is:
WHAT DO YOU WANT TO DO ?

Do you know what a Connection and a Recordset are ?

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
Thank you all for your patience. I suspect I don't know enough yet in order to ask the question properly.

What I'm trying to do is exactly what tsuji said in his #1 option: [1] If the static views (or even tables or columns) have names actually not beginning with @ (normal case), and that you want to query with dynamic name identifier in an sql, then it is conceivable their names are passed around in some variables which begin with @. However, be always prepared to use prepared-statement/EXEC/EXECUTE type of operations to be successful.

If someone can show me how to write this in code (both SQL when saving the view or query), whichever should work best and in the calling statement. Thanks
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top