Solved

SQL Keyword Key - But also column name

Posted on 2012-03-12
7
298 Views
Last Modified: 2012-03-14
Hi all,

I have a column named Key - but when trying to do this:
declare @userID varchar(15)
@userID = (SELECT Key from inserted)

I get an error as "Key" is a keyword, how do I get the info I want from the column and get around this issue with the keyword. As some further help this is the design of the table:

[Key] varchar(15)


I am really new to SQL so any help would be great.


Dan
0
Comment
Question by:EastThames
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
7 Comments
 
LVL 29

Accepted Solution

by:
sammySeltzer earned 500 total points
ID: 37710820
it is keyword.

You can walk around it by wrapping it with []

declare @userID varchar(15)
@userID = (SELECT [Key] from inserted)
0
 
LVL 34

Expert Comment

by:Norie
ID: 37710824
Dan

You can probably get round this by enclosing in [].

But why not rename the column to avoid any further problems?
0
 
LVL 1

Author Comment

by:EastThames
ID: 37710853
SET @userID = (SELECT [Key] from inserted)
gives:Invalid column name 'Key'.

@imnorie I am so new I do not dare touch it just yet :) I dont want to tamper with a external persons DB which I am applying the trigger on.
0
Free eBook: Backup on AWS

Everything you need to know about backup and disaster recovery with AWS, for FREE!

 
LVL 29

Assisted Solution

by:sammySeltzer
sammySeltzer earned 500 total points
ID: 37710888
then that key doesn't exist on the db or it belongs to a different table.

otherwise, it would have worked
0
 
LVL 34

Expert Comment

by:Norie
ID: 37710890
Enclosing in [] works for me.
0
 
LVL 34

Expert Comment

by:Norie
ID: 37710894
By the way, where are you running this code?
0
 
LVL 25

Expert Comment

by:jogos
ID: 37710935
<< from inserted>>
it will be in a trigger

but <<@imnorie I am so new I do not dare touch it just yet :) I dont want to tamper with a external persons DB which I am applying the trigger on.>>
say's otherwise
0

Featured Post

U.S. Department of Agriculture and Acronis Access

With the new era of mobile computing, smartphones and tablets, wireless communications and cloud services, the USDA sought to take advantage of a mobilized workforce and the blurring lines between personal and corporate computing resources.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Use this article to create a batch file to backup a Microsoft SQL Server database to a Windows folder.  The folder can be on the local hard drive or on a network share.  This batch file will query the SQL server to get the current date & time and wi…
This article describes how to use the timestamp of existing data in a database to allow Tableau to calculate the prior work day instead of relying on case statements or if statements to calculate the days of the week.
There are cases when e.g. an IT administrator wants to have full access and view into selected mailboxes on Exchange server, directly from his own email account in Outlook or Outlook Web Access. This proves useful when for example administrator want…
In this video, viewers are given an introduction to using the Windows 10 Snipping Tool, how to quickly locate it when it's needed and also how make it always available with a single click of a mouse button, by pinning it to the Desktop Task Bar. Int…

691 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question