all groups > sql server (alternate) > august 2007 >
You're in the

sql server (alternate)

group:

help with while loops


help with while loops lhiregoudar NO[at]SPAM hotmail.com
8/23/2007 1:58:14 PM
sql server (alternate): hi,
I am trying to
1)get all the names of a table that match another table
2)while count=0, then I want to insert into another table 'group'
after getting its key.

I am totally lost, can somebody point me in the right direction.

how do I get the individual name so that I can insert into the group
table,
I tried 'select @name=name, that gave no results'.
Thanks

while (SELECT name FROM names WHERE name in (select name from Group)
and status = 'M' )=0
begin
insert into CAll(group_id,name,action) values (@key, name, 'play' )
end

how do i get the individual names to insert into another table ..
Re: help with while loops Erland Sommarskog
8/23/2007 9:56:56 PM
(lhiregoudar@hotmail.com) writes:
[quoted text, click to view]

You are the only one who is lost. I am also lost in trying to understand
what you want to achieve. A standard recommendation is that you post:

o CREATE TABLE statements for your tables.
o INSERT statements with sample data.
o The desired result given the sample.



--
Erland Sommarskog, SQL Server MVP, esquel@sommarskog.se

Books Online for SQL Server 2005 at
http://www.microsoft.com/technet/prodtechnol/sql/2005/downloads/books.mspx
Books Online for SQL Server 2000 at
Re: help with while loops David Portas
8/23/2007 11:43:46 PM
[quoted text, click to view]

Why would you need a loop to do that? I don't think you will because you can
INSERT multiple rows in one statement:

INSERT INTO tbl1 (col1, col2)
SELECT col1, col2 FROM tbl2;

If you need more help, please post DDL, sample data and show your required
end result.

--
David Portas, SQL Server MVP

Whenever possible please post enough code to reproduce your problem.
Including CREATE TABLE and INSERT statements usually helps.
State what version of SQL Server you are using and specify the content
of any error messages.

SQL Server Books Online:
http://msdn2.microsoft.com/library/ms130214(en-US,SQL.90).aspx
--

AddThis Social Bookmark Button