Solved

SQL Keyword Key - But also column name

Posted on 2012-03-12
7
287 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
Comment Utility
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
Comment Utility
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
Comment Utility
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
How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

 
LVL 28

Assisted Solution

by:sammySeltzer
sammySeltzer earned 500 total points
Comment Utility
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
Comment Utility
Enclosing in [] works for me.
0
 
LVL 33

Expert Comment

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

Expert Comment

by:jogos
Comment Utility
<< 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

What is SQL Server and how does it work?

The purpose of this paper is to provide you background on SQL Server. It’s your self-study guide for learning fundamentals. It includes both the history of SQL and its technical basics. Concepts and definitions will form the solid foundation of your future DBA expertise.

Join & Write a Comment

Introduction Hopefully the following mnemonic and, ultimately, the acronym it represents is common place to all those reading: Please Excuse My Dear Aunt Sally (PEMDAS). Briefly, though, PEMDAS is used to signify the order of operations (http://en.…
Data architecture is an important aspect in Software as a Service (SaaS) delivery model. This article is a study on the database of a single-tenant application that could be extended to support multiple tenants. The application is web-based develope…
Illustrator's Shape Builder tool will let you combine shapes visually and interactively. This video shows the Mac version, but the tool works the same way in Windows. To follow along with this video, you can draw your own shapes or download the file…
Here's a very brief overview of the methods PRTG Network Monitor (https://www.paessler.com/prtg) offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…

728 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

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now