not permitted in this context

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Kivak

    not permitted in this context

    Hi,

    I am having a SQL Server 2005 problem with my Insert statement. I am
    sending a command via my website to my database. It comes up with an
    error I'll put below. The code is here:

    "INSERT INTO tblUsers (userName) VALUES ( userNameTest)"

    This is the error I get:

    The name "userNameTe st" is not permitted in this context. Valid
    expressions are constants, constant expressions, and (in some contexts)
    variables. Column names are not permitted.

    Now, userName is a varchar field in the database. What is wrong?

    Kivak

  • blueghost73@yahoo.com

    #2
    Re: not permitted in this context


    Kivak wrote:
    Hi,
    >
    I am having a SQL Server 2005 problem with my Insert statement. I am
    sending a command via my website to my database. It comes up with an
    error I'll put below. The code is here:
    >
    "INSERT INTO tblUsers (userName) VALUES ( userNameTest)"
    >
    This is the error I get:
    >
    The name "userNameTe st" is not permitted in this context. Valid
    expressions are constants, constant expressions, and (in some contexts)
    variables. Column names are not permitted.
    >
    Now, userName is a varchar field in the database. What is wrong?
    >
    Kivak
    I'm no expert, so I'm just guessing here, but there are two things I'd
    look for. First, is your userNameTest in quotes inside those
    parentheses? Second, is there a column in the table that is called
    userNameTest?

    --Richard

    Comment

    • Roy Harvey

      #3
      Re: not permitted in this context

      >userName is a varchar field in the database

      Columns are in tables, tables are in a database. It is meaningless to
      refer to a column without the context of a table. The only table
      specified in your sample code is tblUsers, but that is the target of
      the INSERT, not a source of data.

      The version of INSERT that uses the VALUES clause expects values for a
      single new row to be inserted. Those values can be constants, 'John
      Smith' or 345, constant expressions, 'John ' + 'Smith' or 300 + 45, or
      @variables.

      The other version of INSERT replaces the VALUES() clause with a
      SELECT. That version will insert as many rows as are returned by the
      SELECT. If your purpose was to insert all userName values from
      another table into tblUsers this might be the syntax you need:

      INSERT INTO tblUsers (userName)
      SELECT userNameTest FROM tblTestUsers

      Roy Harvey
      Beacon Falls, CT

      On 18 Jul 2006 20:44:07 -0700, "Kivak" <LittleWolfee@g mail.comwrote:
      >Hi,
      >
      >I am having a SQL Server 2005 problem with my Insert statement. I am
      >sending a command via my website to my database. It comes up with an
      >error I'll put below. The code is here:
      >
      >"INSERT INTO tblUsers (userName) VALUES ( userNameTest)"
      >
      >This is the error I get:
      >
      >The name "userNameTe st" is not permitted in this context. Valid
      >expressions are constants, constant expressions, and (in some contexts)
      >variables. Column names are not permitted.
      >
      >Now, userName is a varchar field in the database. What is wrong?
      >
      >Kivak

      Comment

      Working...