473,378 Members | 1,312 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,378 software developers and data experts.

table's name in a variable - in sql stmt

3
hi
can any one help me how to construct an sql select statement in which the table's name , i'm givin it in a variable

Tbl="eng_class6" or sometimes Tbl="maths_class6" , so I want data from diiferent tables.

Cmd.CommandText = "select * from " & Tbl & " where questno =" & arrRndNos(i) & ""
Cmd.CommandType = adCmdTable
Set RS = Cmd.Execute

Is it possible?
this gives me the error in FROM clause.
thanks
Nov 26 '06 #1
3 3457
Killer42
8,435 Expert 8TB
can any one help me how to construct an sql select statement in which the table's name , i'm givin it in a variable
Tbl="eng_class6" or sometimes Tbl="maths_class6" , so I want data from diiferent tables.
Cmd.CommandText = "select * from " & Tbl & " where questno =" & arrRndNos(i) & ""
Cmd.CommandType = adCmdTable
Set RS = Cmd.Execute
Is it possible?
this gives me the error in FROM clause.
thanks
The general idea seem alright, so the problem is likely to be in the specific details of this case. Can you tell us the exact error message? And can you set a break point or something, and display the value of Tbl to check for certain what's in it? (You could also use Debug.Print, or whatever).

It might help (or might not) help if you put square brackets around the table name. For example, "[maths_class6]" instead of "maths_class6".

It might help to know what environment you're working in, too. For example, VB6, VB.Net, VBA in MS Access, etc.

Um... You might also try adding a semicolon (;) on the end of the string - don't know whether it will help or not. Is that what was supposed to be in that empty string you're appending?
Nov 26 '06 #2
jincep
3
hi, it works with this.

Cmd.CommandText = "select * from " & Tbl & " where questno =" & arrRndNos(1) & ";"
Cmd.CommandType = adCmdText
Set RS = Cmd.Execute

thank you so much
Nov 27 '06 #3
Killer42
8,435 Expert 8TB
hi, it works with this.
Cmd.CommandText = "select * from " & Tbl & " where questno =" & arrRndNos(1) & ";"
Cmd.CommandType = adCmdText
Set RS = Cmd.Execute
thank you so much
So the problem must have been either the semicolon, or the value of i.
Nov 27 '06 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

3
by: Martin Lucas-Smith | last post by:
Can anyone point me to a regular expression in PHP which could be used to check that a proposed (My)SQL database/table/column name is valid, i.e. shouldn't result in an SQL error when created? ...
11
by: Jack | last post by:
I want to display a table on a page based on whether a button is pressed or not. I'm new at php so I'm sure I'm making a basic mistake. Here's what I am trying. My thought was that $show_summary...
2
by: LVande | last post by:
SQLLY challenged be gentle -- Trying to create code that will drop a table using a variable as the Table Name. DECLARE @testname as char(50) SELECT @testname = 'CO_Line_of_Business_' +...
2
by: Saiyou Anh | last post by:
I know passing table/column name as parameter to a stored procedure is not good practice, but sometimes I need to do that occasionally. I know there's a way can do that but forget how. Can someone...
1
by: adit | last post by:
Is there anyway I can query on a table that is present within another variable? This is the situation: I get a table name from a column 'TBNAME' from the catalog table SYSCOLUMNS and I would like...
1
by: William Herring | last post by:
I would like to create a temporary table with a variable name. For example, the name of the table might be based on some form of datetime and a constant text. I have looked through the logs, but...
3
by: prabhukumarasamy | last post by:
Now i m working in a existing project. I have to do some updations. In that project database table contain a table(usergroups) field name as 'Name'. When i am trying to insert a new record in...
3
by: adiel_g | last post by:
Hello everyone, I am trying to move a field name to a variable in vb.net. For example, first I retrieve the record from the database and save its value: .... userGroup =...
3
by: dmorand | last post by:
I'm very new to stored procedures so this is probably something very dumb. I want to pass a name of a table to be created to my stored procedure. I'm using the variable @tableName in the code below...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.