SQL Server Forums
Profile | Register | Active Topics | Members | Search | Forum FAQ
 
Register Now and get your question answered!
Username:
Password:
Save Password
Forgot your Password?

 All Forums
 SQL Server 2005 Forums
 Transact-SQL (2005)
 Insert query subqueries
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

cplusplus
Aged Yak Warrior

541 Posts

Posted - 06/15/2009 :  12:14:20  Show Profile  Reply with Quote
I am trying to use this insert query, getting error message sub queries are not allowed in this type, can you please tell me is there any other way to include all of the subqueries.

		Insert into Tab_ccsNetTaskPercentHistory
		(percentcomplete,
			datepctcomplete,
			divisionid,
			progid,
			projid,
			phase_id,
			element_id,
			ContractID,
			taskid,
			createdby) values(@PctComplete,@pctCompleteDate,(select top 1 divisionid from Tab_ccsnetTasks WHERE Taskid = @TaskID),
				(select top 1 progid from Tab_ccsnetTasks WHERE Taskid = @TaskID),
				(select top 1 projid from Tab_ccsnetTasks WHERE Taskid = @TaskID),
				(select top 1 phase_id from Tab_ccsnetTasks WHERE Taskid = @TaskID),
				(select top 1 element_id from Tab_ccsnetTasks WHERE Taskid = @TaskID),
				(select top 1 contractid from Tab_ccsnetTasks WHERE Taskid = @TaskID),@TaskID,@UserName)


Thank you very much for the help.

webfred
Flowing Fount of Yak Knowledge

Germany
8766 Posts

Posted - 06/15/2009 :  13:02:17  Show Profile  Visit webfred's Homepage  Reply with Quote
make a select and use it instead of VALUES


No, you're never too old to Yak'n'Roll if you're too young to die.
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

India
52325 Posts

Posted - 06/15/2009 :  14:26:13  Show Profile  Reply with Quote

Insert into Tab_ccsNetTaskPercentHistory
		(percentcomplete,
			datepctcomplete,
			divisionid,
			progid,
			projid,
			phase_id,
			element_id,
			ContractID,
			taskid,
			createdby) 
SELECT top 1  @PctComplete,@pctCompleteDate,divisionid ,progid ,projid ,phase_id ,
element_id ,contractid ,@TaskID,@UserName from Tab_ccsnetTasks WHERE Taskid = @TaskID


please keep in mind that unless you give an explicit order using order by this just returns you values from a random record as sql table doesnt have concept of first and last
Go to Top of Page
  Previous Topic Topic Next Topic  
 New Topic  Reply to Topic
 Printer Friendly
Jump To:
SQL Server Forums © 2000-2009 SQLTeam Publishing, LLC Go To Top Of Page
This page was generated in 0.06 seconds. Powered By: Snitz Forums 2000