General SQL Development
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
 
User Name:
Password:
Remember me
 



Go Back   Dev Articles Community ForumsDatabasesGeneral SQL Development

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Display Modes
 
Unread Dev Articles Community Forums Sponsor:
  #1  
Old May 15th, 2013, 04:52 AM
menssanvi menssanvi is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Apr 2013
Posts: 6 menssanvi User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 4 m 7 sec
Reputation Power: 0
Create Looping in SQL

I'm trying to create a loop/cursor that will help me do an update as long as wh_no matches and the cluster no doesnt' (see sql). Any help will be much appreciated.
-----------------
UPDATE t_m_re_temp
FROM
(
SELECT
Wh_No ,
MIN(cluster_no)
FROM
t_m_re_temp
GROUP BY Wh_No
) AS TEST (D1,D2)
SET cluster_no = d2
WHERE
Wh_No = D1
AND CLUSTER_NO <> D2


---------------

Reply With Quote
  #2  
Old May 15th, 2013, 11:16 AM
bitsmed bitsmed is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Jun 2012
Posts: 11 bitsmed User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 h 59 m 53 sec
Reputation Power: 0
From the top of my head, this might point you in the right direction:
Code:
update t_m_re_temp
   set t_m_re_temp.cluster_no=b.cluster_no
  from t_m_re_tempas a
       inner join (select wh_no
                         ,min(cluster_no) as cluster_no
                     from t_m_re_tempas
                    group by wh_no
                  ) as b
               on b.wh_no=a.wh_no
              and b.cluster_no<>a.cluster_no

The above sql has not been tested, as I currently only have access to notepad

Reply With Quote
Reply

Viewing: Dev Articles Community ForumsDatabasesGeneral SQL Development > Create Looping in SQL


Developer Shed Advertisers and Affiliates


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


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
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 


Powered by: vBulletin Version 3.0.5
Copyright ©2000 - 2017, Jelsoft Enterprises Ltd.

© 2003-2017 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap