all groups > sql server misc > october 2003 >
You're in the

sql server misc

group:

insert error ('name is not permitted in this context...')


insert error ('name is not permitted in this context...') frank brown
10/2/2003 5:26:25 PM
sql server misc:
When I submit the following TSQL to SqlServer 2000/SP3:

INSERT dispinfo (datetime,incno,alarm,units,loc,type,insType)
VALUES ("9/29/2003 01:36","F041069908","1","AU32","3052 NW 134 ST #2
,SEA","AFA (AUTO. FIRE ALARM)",2)

it fails with the following error:

Server: Msg 128, Level 15, State 1, Line 2
The name '9/29/2003 01:36' is not permitted in this context. Only constants,
expressions, or variables allowed here. Column names are not permitted.

The first field in table dispinfo is named datetime of datatype datetime.
Why isn't Sqlserver accepting this INSERT statement?

-Frank Brown
Seattle Fire Dept
http://www.inwa.net/~frog/

Re: insert error ('name is not permitted in this context...') David Portas
10/2/2003 7:19:22 PM
SQL uses single rather than double quotes as string delimiters:

INSERT INTO dispinfo
([datetime], incno, alarm, units, loc, type, insType)
VALUES ('2003-09-29T01:36:00','F041069908','1','AU32',
'3052 NW 134 ST #2,SEA','AFA (AUTO. FIRE ALARM)',2)

"Datetime" is a reserved word and shouldn't be used as a column name, but if
you must then enclose it in square brackets.

Always specify datetimes in the ISO format shown above which will work
independently of any regional settings.

--
David Portas
------------
Please reply only to the newsgroup
--

Re: insert error ('name is not permitted in this context...') frank brown
10/3/2003 2:52:29 PM
David,

This is useful information. I am using double rather than single quotes for
delimiters because occasionally single quotes appear inside value strings.
If I must delimit using single quotes, what is the recommended method for
embedding a single quote inside a string thus delimited?

-Frank

Thus spake "David Portas":

[quoted text, click to view]

Re: insert error ('name is not permitted in this context...') David Portas
10/3/2003 8:01:07 PM
Use two single quotes. SQL will read this is a single quote:

SELECT 'David''s, Frank''s'

--
David Portas
------------
Please reply only to the newsgroup
--

AddThis Social Bookmark Button