Solved

SQL Keyword Key - But also column name

Posted on 2012-03-12
7
291 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
7 Comments
 
LVL 28

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 33

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
The New “Normal” in Modern Enterprise Operations

DevOps for the modern enterprise offers many benefits — increased agility, productivity, and more, but digital transformation isn’t easy, especially if you’re not addressing the right issues. Register for the webinar to dive into the “new normal” for enterprise modern ops.

 
LVL 28

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 33

Expert Comment

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

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

Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

Question has a verified solution.

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

'Between' is such a common word we rarely think about it but in SQL it has a very specific definition we should be aware of. While most database vendors will have their own unique phrases to describe it (see references at end) the concept in common …
In this article I will describe the Backup & Restore method as one possible migration process and I will add the extra tasks needed for an upgrade when and where is applied so it will cover all.
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…

792 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