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

The Shed is going Social! Join us on FaceBook and Twitter and chime in on the conversation.

Go Back   Dev Shed ForumsDatabasesMS SQL Development

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old July 11th, 2012, 01:16 PM
MSSQLNewBie MSSQLNewBie is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jul 2012
Posts: 1 MSSQLNewBie User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 9 m 22 sec
Reputation Power: 0
Update Question

Hi

I have a table which I need to update to value of Y, but this update is based upon some results from other tables, and I am not sure how to do this.

Basically, I need to complete the following checks

1) I need to check from the table I need to update that the other table has exactly 19 matching rows
2) In those matching rows that one of the fields is not null
3) I have two other tables which I need to check that records exist in the latter table plus to ensure that the matching records in the latter do not contain the value of "Y" in one of the fields.

My approach to this is to use UNIONs, but I would like someone to advise me whether this approach is correct or whether there is a much better way of doing it:

SELECT '1'
FROM t_A_Outbound
Where NOT HEADER IN (Select HEADER
FROM t_B_Outbound)
UNION
SELECT '1'
FROM t_A_Outbound
Where HEADER IN (Select HEADER
FROM t_B_Outbound
WHERE NOT INCOMPLETE ='Y')
UNION
Select '1'
From t_C_Outbound
Where ValueString = ''
UNION
Select '1'
From t_C_Outbound
WHERE Exists(Select Count(key), HEADER
From t_C_Outbound IN (SELECT HEADER FROM table_that_needs_updating)
Group By HEADER
Having NOT Count(Cast(key as Int)) = 19)

I thought of using 1 as flag to say if this value comes back to update the field in the table I need to change.

Can anyone advise me?

Reply With Quote
Reply

Viewing: Dev Shed ForumsDatabasesMS SQL Development > Update Question

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 - 2013, Jelsoft Enterprises Ltd.

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