Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2005 Forums
 Transact-SQL (2005)
 Insert query subqueries

Author  Topic 

cplusplus
Aged Yak Warrior

567 Posts

Posted - 2009-06-15 : 12:14:20
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
Master Smack Fu Yak Hacker

8781 Posts

Posted - 2009-06-15 : 13:02:17
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

52326 Posts

Posted - 2009-06-15 : 14:26:13
[code]
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
[/code]

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
   

- Advertisement -