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 November 28th, 2012, 11:26 AM
martynhsmith martynhsmith is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Nov 2012
Posts: 2 martynhsmith User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 12 m 58 sec
Reputation Power: 0
Update using a subquery

I have this SQL

Code:
select zero.ftr_dbtc, zero.ftr_tref,
(select [InvoiceNumber] from  [InterfaceLive].[dbo].[SITS_FeesImport] datlines where
zero.ftr_pstd=datlines.ftr_pstd and left(zero.ftr_scjc,7)= datlines.[ftr_dbtc]) as invoicenumber
from SITS_FeesImport_ZeroInv zero where BursaryType='Textline' 


it uses two tables, I use values in feesimport_zeroinv table to get the value of invoicenumber from the feesimport table

It works but what I really want to do is update the invoicenumber in feesimport_zeroinv but I can't get it to work

Something like this (this doesn't work)
Code:
update SITS_FeesImport_ZeroInv zero     
set [InvoiceNumber]= (select [InvoiceNumber] from  [InterfaceLive].[dbo].[SITS_FeesImport] datlines where zero.ftr_pstd=datlines.ftr_pstd and left(zero.ftr_scjc,7)= datlines.[ftr_dbtc]) 
where BursaryType='Textline' 


Any help most appreciated

M

Reply With Quote
  #2  
Old November 28th, 2012, 02:19 PM
r937's Avatar
r937 r937 is offline
SQL Consultant
Click here for more information.
 
Join Date: Feb 2003
Location: Toronto Canada
Posts: 26,375 r937 User rank is General 47th Grade (Above 100000 Reputation Level)r937 User rank is General 47th Grade (Above 100000 Reputation Level)r937 User rank is General 47th Grade (Above 100000 Reputation Level)r937 User rank is General 47th Grade (Above 100000 Reputation Level)r937 User rank is General 47th Grade (Above 100000 Reputation Level)r937 User rank is General 47th Grade (Above 100000 Reputation Level)r937 User rank is General 47th Grade (Above 100000 Reputation Level)r937 User rank is General 47th Grade (Above 100000 Reputation Level)r937 User rank is General 47th Grade (Above 100000 Reputation Level)r937 User rank is General 47th Grade (Above 100000 Reputation Level)r937 User rank is General 47th Grade (Above 100000 Reputation Level)r937 User rank is General 47th Grade (Above 100000 Reputation Level)r937 User rank is General 47th Grade (Above 100000 Reputation Level)r937 User rank is General 47th Grade (Above 100000 Reputation Level)r937 User rank is General 47th Grade (Above 100000 Reputation Level)r937 User rank is General 47th Grade (Above 100000 Reputation Level) 
Time spent in forums: 3 Months 1 Week 2 Days 7 h 30 m 23 sec
Reputation Power: 4140
Code:
UPDATE SITS_FeesImport_ZeroInv      
   SET InvoiceNumber = datlines.InvoiceNumber
  FROM SITS_FeesImport_ZeroInv AS zero
INNER
  JOIN InterfaceLive.dbo.SITS_FeesImport AS datlines 
    ON datlines.ftr_pstd = zero.ftr_pstd
   AND datlines.ftr_dbtc = LEFT(zero.ftr_scjc,7) 
 WHERE zero.BursaryType = 'Textline' 
__________________
r937.com | rudy.ca
please visit Simply SQL and buy my book

Reply With Quote
  #3  
Old November 29th, 2012, 07:10 AM
martynhsmith martynhsmith is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Nov 2012
Posts: 2 martynhsmith User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 12 m 58 sec
Reputation Power: 0
Quote:
Originally Posted by r937
Code:
UPDATE SITS_FeesImport_ZeroInv      
   SET InvoiceNumber = datlines.InvoiceNumber
  FROM SITS_FeesImport_ZeroInv AS zero
INNER
  JOIN InterfaceLive.dbo.SITS_FeesImport AS datlines 
    ON datlines.ftr_pstd = zero.ftr_pstd
   AND datlines.ftr_dbtc = LEFT(zero.ftr_scjc,7) 
 WHERE zero.BursaryType = 'Textline' 


Thank you, that works perfectly

Reply With Quote
Reply

Viewing: Dev Shed ForumsDatabasesMS SQL Development > Update using a subquery

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