Unix Technical Forum

help with while loops

This is a discussion on help with while loops within the SQL Server forums, part of the Microsoft SQL Server category; --> hi, I am trying to 1)get all the names of a table that match another table 2)while count=0, then ...


Go Back   Unix Technical Forum > Database Server Software > Microsoft SQL Server > SQL Server

FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 03-01-2008, 03:40 PM
lhiregoudar@hotmail.com
 
Posts: n/a
Default help with while loops

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 ..

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #2 (permalink)  
Old 03-01-2008, 03:40 PM
Erland Sommarskog
 
Posts: n/a
Default Re: help with while loops

(lhiregoudar@hotmail.com) writes:
> 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 ..


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/pro...ads/books.mspx
Books Online for SQL Server 2000 at
http://www.microsoft.com/sql/prodinf...ons/books.mspx
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #3 (permalink)  
Old 03-01-2008, 03:40 PM
David Portas
 
Posts: n/a
Default Re: help with while loops

<lhiregoudar@hotmail.com> wrote in message
news:1187902694.528964.278210@m37g2000prh.googlegr oups.com...
> 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 ..
>


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/m...S,SQL.90).aspx
--


Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On
Forum Jump


All times are GMT. The time now is 01:38 PM.


Powered by vBulletin® Version 3.6.5
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.2.0
www.UnixAdminTalk.com