mbt masai
 
Welcome !
         

                                
After experiencing a lot of down time, We decided to move this site to CrystalTech.com. CrystalTech.com is powered by only the finest Windows servers providing the best performance, reliability, and value anywhere.

 Can a SQL statement take a table name as parameter?

Author Message
amir1359

  • Total Posts : 2
  • Scores: 0
  • Reward points : 0
  • Joined: 12/12/2009
  • Status: offline
Can a SQL statement take a table name as parameter? Saturday, December 12, 2009 7:20 PM (permalink)
0
Hi
i am sure there is way to get the table name as a parameter but i could not find the correct syntax

<%
Dim rs
Dim rs_numRows
Dim dynamicTable // this is the var which keep my parameter posted by querystring (which is tableName)
dynamicTable =request("tableName")
 

Set rs = Server.CreateObject("ADODB.Recordset")
'rs.ActiveConnection = MM_conn1_STRING // this is my conn string to open the record set
rs.Source = "SELECT * FROM " + dynamicTable // this is my broblem
'rs.Source = "SELECT * FROM ComplainList"

rs.CursorType = 0
rs.CursorLocation = 2
rs.LockType = 1
rs.Open()

rs_numRows = 0
%>

As i have mentioned in the code the time which i use "SELECT * FROM ComplainList" as my source , i dont have any problem but the time i use "SELECT * FROM " + dynamicTable .. i get syntax error which say FROM clause syntax error!!

please teach me ,what to do??
 
#1
    centauricw

    • Total Posts : 42
    • Scores: 2
    • Reward points : 0
    • Joined: 2/20/2006
    • Status: offline
    Re:Can a SQL statement take a table name as parameter? Friday, December 25, 2009 2:02 PM (permalink)
    0
    Instead of

    rs.Source = "SELECT * FROM " + dynamicTable

    try

    rs.Source = "SELECT * FROM " & dynamicTable

    The ampersand ( & ) is the correct concatenation operator for joining strings.
    #2

      Online Bookmarks Sharing: Share/Bookmark

      Jump to:

      Current active users

      There are 0 members and 1 guests.

      Icon Legend and Permission

      • New Messages
      • No New Messages
      • Hot Topic w/ New Messages
      • Hot Topic w/o New Messages
      • Locked w/ New Messages
      • Locked w/o New Messages
      • Read Message
      • Post New Thread
      • Reply to message
      • Post New Poll
      • Submit Vote
      • Post reward post
      • Delete my own posts
      • Delete my own threads
      • Rate post

      2000-2012 ASPPlayground.NET Forum Version 3.8
      mbt shoes www.wileywilson.com