Help with INSERT query

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
tmccrankAsked:
Who is Participating?
 
Jim HornMicrosoft SQL Server Developer, Architect, and AuthorCommented:

INSERT INTO Feedback(Feedback, UserName)
SELECT 'this is test feedback', UserNameID
FROM SomeTableNameGoesHere
where UserCapitalHealthIdentity = 'ch\JensGerbitz'
0
 
Aneesh RetnakaranDatabase AdministratorCommented:
INSERT INTO Feedback(Feedback, UserName)
SELECT 12, UserNameID
where UserCapitalHealthIdentity = 'ch\JensGerbitz'

0
 
rw3adminCommented:
INSERT INTO Feedback(Feedback, UserName)
Select 'this is test feedback',
           UserNameID
From    Users
where  UserCapitalHealthIdentity = 'ch\JensGerbitz'
0
Ultimate Tool Kit for Technology Solution Provider

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy now.

 
Aneesh RetnakaranDatabase AdministratorCommented:
INSERT INTO Feedback(Feedback, UserName)
SELECT 'this is test feedback', UserNameID
where UserCapitalHealthIdentity = 'ch\JensGerbitz'
0
 
rw3adminCommented:
Aneesh... you need some sleep now :) its the second comment where you have missed "from Table" part :)
0
 
Aneesh RetnakaranDatabase AdministratorCommented:
rw3admin,
> Aneesh... you need some sleep now :)
hmmm .... i am alredy on the bed (its  12.00 am in Bangalore )
0
 
rw3adminCommented:
Then go :)...
Watch some good Shahrukh Khan movie and go to sleep ........ :)

goodnight
0
 
tmccrankAuthor Commented:
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
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.