July 11, 2008 at 9:58 am
can i do this insert
INSERT INTO @GroupId, @GroupName, @ZoneInstanceId, @ScoreType
SELECT ItemId,InspectionItemName,ZoneInstanceId,ScoreTypeId from InspectionGroup
ORDER BY InspectionItemName
here InspectionGroup is a CTE
July 11, 2008 at 10:16 am
I haven't worked with common table expressions much, but wondering if you are trying to get the values into array variables?? The only way I've done that is through table variables, but if your are just wanting a specific row to be set tot he 4 variables use something like SELECT @var1 = Col1, @var2 = col2, ...
July 11, 2008 at 10:44 am
If you're trying add these values to a CTE, wouldn't you use UNION? Probably in a second CTE.
"The credit belongs to the man who is actually in the arena, whose face is marred by dust and sweat and blood"
- Theodore Roosevelt
Author of:
SQL Server Execution Plans
SQL Server Query Performance Tuning
July 11, 2008 at 6:34 pm
Mike Levan (7/11/2008)
can i do this insertINSERT INTO @GroupId, @GroupName, @ZoneInstanceId, @ScoreType
SELECT ItemId,InspectionItemName,ZoneInstanceId,ScoreTypeId from InspectionGroup
ORDER BY InspectionItemName
here InspectionGroup is a CTE
No... You cannot INSERT into scalar variables... tell us what the entire problem is.
--Jeff Moden
Change is inevitable... Change for the better is not.
July 27, 2008 at 1:16 am
Yes it will surely work
create table aaaa(id int)
insert into aaaa values(1)
insert into aaaa values(2)
insert into aaaa values(3)
select * from aaaa
create table venkat(id int)
with cte as
(
select * from aaaa
)
insert into venkat(id)
select * from cte
select * from venkat
Thanks and Regards,
Venkatesan Prabu, 😛
My Blog:
http://venkattechnicalblog.blogspot.com/
July 27, 2008 at 8:56 am
Good example of an Insert... that's not inserting into a scalar variable, though.
--Jeff Moden
Change is inevitable... Change for the better is not.
July 27, 2008 at 9:28 am
Jeff is right. You cannot insert into scalars. you can reassign variables (as in my first post), but INSERT is only for Table(like) structures.
Viewing 8 posts - 1 through 7 (of 7 total)
You must be logged in to reply to this topic. Login to reply