SQL Server Forums
Profile | Register | Active Topics | Members | Search | Forum FAQ
 
Register Now and get your question answered!
Username:
Password:
Save Password
Forgot your Password?

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 Update with conditional select.
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

alexellice
Starting Member

13 Posts

Posted - 11/29/2012 :  04:30:39  Show Profile  Reply with Quote

update "THISTABLE"
set col_C = 'S'

from 
(select col_A, col_B, col_C , MAX(col_D) from "THISTABLE" 
group by col_A, col_B, col_C having MAX(col_D) < '19850101') as myData

where THISTABLE.col_A = '2607121497' and THISTABLE.col_B = mydata.col_B and THISTABLE.col_C = 'T'


Hi all.. if anyone has some input on this it would be great.... my hair is all gray beacuse of this!.. Here we're using Pervasiv SQL (but normal SQL should work fine)

All columns are strings and we have no Unique ID to work with :-(

The problem is that when I run this... it says X rows affect... if I run a test query, say:

select col_A, col_B, col_C from "THISTABLE" where col_C = 'T' and col_D < '19850101'

It does not seem to have written to the rows

bandi
Flowing Fount of Yak Knowledge

India
2218 Posts

Posted - 11/29/2012 :  05:09:28  Show Profile  Reply with Quote
quote:
The problem is that when I run this... it says X rows affect... if I run a test query, say:

select col_A, col_B, col_C from "THISTABLE" where col_C = 'T' and col_D < '19850101'

It does not seem to have written to the rows



Post-update how can you see records with col_C = 'T' ? (Actually u r updating 'T' to 'S'.... right?)

--
Chandu
Go to Top of Page

alexellice
Starting Member

13 Posts

Posted - 11/29/2012 :  05:50:17  Show Profile  Reply with Quote
I meant (select col_A, col_B, col_C, col_D from "THISTABLE" where col_C = 'T' and col_D < '19850101'
sorry for the confusing.


And yes... the whole idea of the query is to update all the col_C that have a value of 'T' to 'S' withing the select
Go to Top of Page

bandi
Flowing Fount of Yak Knowledge

India
2218 Posts

Posted - 11/29/2012 :  05:53:38  Show Profile  Reply with Quote
If you want to check the updated rows,

select col_A, col_B, col_C from "THISTABLE" where col_C = 'S' and col_D < '19850101'


--
Chandu
Go to Top of Page

alexellice
Starting Member

13 Posts

Posted - 11/29/2012 :  06:31:45  Show Profile  Reply with Quote
I understand that... but by asking for 'T'... there should not be any rows with 'T'... only 'S'
Go to Top of Page

bandi
Flowing Fount of Yak Knowledge

India
2218 Posts

Posted - 11/29/2012 :  06:38:32  Show Profile  Reply with Quote
quote:
Originally posted by alexellice

I understand that... but by asking for 'T'... there should not be any rows with 'T'... only 'S'


Yes.....


--
Chandu
Go to Top of Page

nigelrivett
Flowing Fount of Yak Knowledge

United Kingdom
3383 Posts

Posted - 11/29/2012 :  07:09:36  Show Profile  Visit nigelrivett's Homepage  Reply with Quote
The updae will only affect rows where col_A = '2607121497'

==========================================
Cursors are useful if you don't know sql.
SSIS can be used in a similar way.
Beer is not cold and it isn't fizzy.
Go to Top of Page
  Previous Topic Topic Next Topic  
 New Topic  Reply to Topic
 Printer Friendly
Jump To:
SQL Server Forums © 2000-2009 SQLTeam Publishing, LLC Go To Top Of Page
This page was generated in 0.06 seconds. Powered By: Snitz Forums 2000