Solved

SQL Keyword Key - But also column name

Posted on 2012-03-12
7
289 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
PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

 
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

Efficient way to get backups off site to Azure

This user guide provides instructions on how to deploy and configure both a StoneFly Scale Out NAS Enterprise Cloud Drive virtual machine and Veeam Cloud Connect in the Microsoft Azure Cloud.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
How can i make query faster by writing T-SQL? 6 35
get column names from table in vb.net 8 26
sql server insert 12 30
performance query 4 20
PL/SQL can be a very powerful tool for working directly with database tables. Being able to loop will allow you to perform more complex operations, but can be a little tricky to write correctly. This article will provide examples of basic loops alon…
Occasionally there is a need to clean table columns, especially if you have inherited legacy data. There are obviously many ways to accomplish that, including elaborate UPDATE queries with anywhere from one to numerous REPLACE functions (even within…
In a recent question (https://www.experts-exchange.com/questions/28997919/Pagination-in-Adobe-Acrobat.html) here at Experts Exchange, a member asked how to add page numbers to a PDF file using Adobe Acrobat XI Pro. This short video Micro Tutorial sh…
Email security requires an ever evolving service that stays up to date with counter-evolving threats. The Email Laundry perform Research and Development to ensure their email security service evolves faster than cyber criminals. We apply our Threat…

786 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