Improve company productivity with a Business Account.Sign Up

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 474
  • Last Modified:

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
0
tmccrank
Asked:
tmccrank
2 Solutions
 
Aneesh RetnakaranDatabase AdministratorCommented:
INSERT INTO Feedback(Feedback, UserName)
SELECT 12, UserNameID
where UserCapitalHealthIdentity = 'ch\JensGerbitz'

0
 
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
 
rw3adminCommented:
INSERT INTO Feedback(Feedback, UserName)
Select 'this is test feedback',
           UserNameID
From    Users
where  UserCapitalHealthIdentity = 'ch\JensGerbitz'
0
Build your data science skills into a career

Are you ready to take your data science career to the next step, or break into data science? With Springboard’s Data Science Career Track, you’ll master data science topics, have personalized career guidance, weekly calls with a data science expert, and a job guarantee.

 
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.

Join & Write a Comment

Featured Post

Get expert help—faster!

Need expert help—fast? Use the Help Bell for personalized assistance getting answers to your important questions.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now