Solved

Help with INSERT query

Posted on 2006-11-15
8
466 Views
Last Modified: 2008-02-01
I'm trying to do a simple insert into a table that collects feedback and tracks who left the feedback.  I have two tables:

Feedback
  FeedbackID int (4)
  Feedback varchar (500)

Users
  UserNameID int (4)
  UserCapitalHealthIdentity varchar (30)

I would like to insert the Feedback and the UserNameID, with the UserNameID pulled from the Users table based on the UserCapitalHealthIdentity.

I'm not great at T-SQL, but thought I would give it a shot:


INSERT INTO Feedback(Feedback, UserName)
VALUES ('this is test feedback',
      (SELECT UserNameID where UserCapitalHealthIdentity = 'ch\JensGerbitz')
      )

Got the following error:

Server: Msg 1046, Level 15, State 1, Line 3
Subqueries are not allowed in this context. Only scalar expressions are allowed.

Any ideas?
Thanks
0
Comment
Question by:tmccrank
8 Comments
 
LVL 75

Expert Comment

by:Aneesh Retnakaran
ID: 17949185
INSERT INTO Feedback(Feedback, UserName)
SELECT 12, UserNameID
where UserCapitalHealthIdentity = 'ch\JensGerbitz'

0
 
LVL 65

Accepted Solution

by:
Jim Horn earned 100 total points
ID: 17949195

INSERT INTO Feedback(Feedback, UserName)
SELECT 'this is test feedback', UserNameID
FROM SomeTableNameGoesHere
where UserCapitalHealthIdentity = 'ch\JensGerbitz'
0
 
LVL 11

Assisted Solution

by:rw3admin
rw3admin earned 100 total points
ID: 17949196
INSERT INTO Feedback(Feedback, UserName)
Select 'this is test feedback',
           UserNameID
From    Users
where  UserCapitalHealthIdentity = 'ch\JensGerbitz'
0
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.

 
LVL 75

Expert Comment

by:Aneesh Retnakaran
ID: 17949197
INSERT INTO Feedback(Feedback, UserName)
SELECT 'this is test feedback', UserNameID
where UserCapitalHealthIdentity = 'ch\JensGerbitz'
0
 
LVL 11

Expert Comment

by:rw3admin
ID: 17949246
Aneesh... you need some sleep now :) its the second comment where you have missed "from Table" part :)
0
 
LVL 75

Expert Comment

by:Aneesh Retnakaran
ID: 17949263
rw3admin,
> Aneesh... you need some sleep now :)
hmmm .... i am alredy on the bed (its  12.00 am in Bangalore )
0
 
LVL 11

Expert Comment

by:rw3admin
ID: 17949285
Then go :)...
Watch some good Shahrukh Khan movie and go to sleep ........ :)

goodnight
0
 

Author Comment

by:tmccrank
ID: 17951082
Thanks... I got the same answer from two of you, so I'll split the massive prize.

aneeshattingal: thanks for your input, I hope you get some sleep!  All the best to Bangalore.

Jens
0

Featured Post

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.

Question has a verified solution.

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

Suggested Solutions

This article explains how to reset the password of the sa account on a Microsoft SQL Server.  The steps in this article work in SQL 2005, 2008, 2008 R2, 2012, 2014 and 2016.
Slowly Changing Dimension Transformation component in data task flow is very useful for us to manage and control how data changes in SSIS.
Familiarize people with the process of utilizing SQL Server functions from within Microsoft Access. Microsoft Access is a very powerful client/server development tool. One of the SQL Server objects that you can interact with from within Microsoft Ac…
Via a live example combined with referencing Books Online, show some of the information that can be extracted from the Catalog Views in SQL Server.

856 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