Solved

Help with INSERT query

Posted on 2006-11-15
8
463 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
 
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
Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

 
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

Get up to 2TB FREE CLOUD per backup license!

An exclusive Black Friday offer just for Expert Exchange audience! Buy any of our top-rated backup solutions & get up to 2TB free cloud per system! Perform local & cloud backup in the same step, and restore instantly—anytime, anywhere. Grab this deal now before it disappears!

Join & Write a Comment

Suggested Solutions

Introduction SQL Server Integration Services can read XML files, that’s known by every BI developer.  (If you didn’t, don’t worry, I’m aiming this article at newcomers as well.) But how far can you go?  When does the XML Source component become …
Introduction In my previous article (http://www.experts-exchange.com/Microsoft/Development/MS-SQL-Server/SSIS/A_9150-Loading-XML-Using-SSIS.html) I showed you how the XML Source component can be used to load XML files into a SQL Server database, us…
Using examples as well as descriptions, and references to Books Online, show the documentation available for datatypes, explain the available data types and show how data can be passed into and out of variables.
Viewers will learn how to use the SELECT statement in SQL to return specific rows and columns, with various degrees of sorting and limits in place.

746 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

12 Experts available now in Live!

Get 1:1 Help Now