Solved

Help with INSERT query

Posted on 2006-11-15
8
468 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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 66

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
Simplifying Server Workload Migrations

This use case outlines the migration challenges that organizations face and how the Acronis AnyData Engine supports physical-to-physical (P2P), physical-to-virtual (P2V), virtual to physical (V2P), and cross-virtual (V2V) migration scenarios to address these challenges.

 
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

Complete VMware vSphere® ESX(i) & Hyper-V Backup

Capture your entire system, including the host, with patented disk imaging integrated with VMware VADP / Microsoft VSS and RCT. RTOs is as low as 15 seconds with Acronis Active Restore™. You can enjoy unlimited P2V/V2V migrations from any source (even from a different hypervisor)

Question has a verified solution.

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

Everyone has problem when going to load data into Data warehouse (EDW). They all need to confirm that data quality is good but they don't no how to proceed. Microsoft has provided new task within SSIS 2008 called "Data Profiler Task". It solve th…
Ever needed a SQL 2008 Database replicated/mirrored/log shipped on another server but you can't take the downtime inflicted by initial snapshot or disconnect while T-logs are restored or mirror applied? You can use SQL Server Initialize from Backup…
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…
Viewers will learn how the fundamental information of how to create a table.

624 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