|
Posted by Roy Harvey on 07/19/06 11:10
>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@gmail.com> 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 "userNameTest" 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
Navigation:
[Reply to this message]
|