Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

The name "X" is not permitted in this context. Valid expressions are constants, constant expressions, and variables. Column names are not permitted

Tags:

sql

sql-server

Using SQL Server. I am getting an error from an SQL Insert statement:

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

This is the Insert SQL that produces that error:

Insert Into [PlanFinder].[ReportLinks]
(TypeOfReport, Links) Values (InvalidAwps, \\uafc.com\ReportLinks\InvalidAwps);

And here is the table definition:

Create Table [PlanFinder].[ReportLinks]
(
  [TypeOfReport]      Char (11)             Not Null,
  [Links]             Money                 Null,
  Constraint pk_TypeOfReport Primary Key Clustered (TypeOfReport)
)

How do I fix this?

like image 699
User7354632781 Avatar asked Sep 21 '10 14:09

User7354632781


3 Answers

You need string delimiters

Insert Into [PlanFinder].[ReportLinks]
(TypeOfReport, Links) Values ('InvalidAwps', '\\uafc.com\ReportLinks\InvalidAwps')

However, then you'll get errors inserting the string \\uafc.com\ReportLinks\InvalidAwps into a money column...

or are \\\InvalidAwps,\\\Missing meant to be symbols of some kind?

like image 97
gbn Avatar answered Nov 11 '22 20:11

gbn


Try putting InvalidAwps in single quotes:

Insert Into [PlanFinder].[ReportLinks] (TypeOfReport, Links) 
Values ('InvalidAwps', '\uafc.com\ReportLinks\InvalidAwps')
like image 43
JNK Avatar answered Nov 11 '22 21:11

JNK


Reproduce this error in SQL Server.

Create a string column and use Double quotes to insert values instead of single quotes:

create table yar (id VARCHAR(50));
insert into yar values("yarrrr");

Causes error:

Msg 128, Level 15, State 1, Line 1
The name "yarrrr" is not permitted in this context. Valid expressions are 
constants, constant expressions, and (in some contexts) variables. Column names 
are not permitted.

Fix it by using single quotes like this:

create table yar (id VARCHAR(50));
insert into yar values('yarrrr');

Prints:

(1 row(s) affected)
like image 1
Eric Leschinski Avatar answered Nov 11 '22 22:11

Eric Leschinski