473,416 Members | 1,675 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,416 software developers and data experts.

Updating a table starting with the first empty column in a specific row

Hi,
I'm struggling to find a solution to this (very likely simple) problem:

I have 2 tables (say A and B). I want to populate some rows in B with information from A. I want the update query to start from the first row were column1 is empty, downwards. Tried to use cursor but wasn't successful. Any help is much appreciated.
Aug 4 '10 #1
4 2502
gpl
152 100+
What do you mean by downwards ? There is no* default order in a table, what sort order do you really mean ?

*actually, there is the order that the rows were inserted, but if you have a clustered index then that order would override the insertion order
Aug 5 '10 #2
ck9663
2,878 Expert 2GB
Try something like:

Expand|Select|Wrap|Line Numbers
  1. UPDATE A
  2. SET
  3. A.COL1 = ISNULL(A.COL1, B.COL1),
  4. A.COL2 = ISNULL(A.COL2, B.COL2),
  5. A.COL3 = ISNULL(A.COL3, B.COL3) 
  6. FROM TABLEA A
  7. INNER JOIN TABLEB B ON A.KEY = B.KEY
  8.  
Now, this code will only update your column if it's currently NULL. Technically, it will update even if it's not null. However, if it's not null, it will update with the current value.

Good Luck!!!

~~ CK
Aug 5 '10 #3
NeoPa
32,556 Expert Mod 16PB
If I understand your question correctly then I'm not sure if this could be done using SQL alone.

If it were an Access question I'd say to use recordset processing in VBA. Something similar may be possible with a cursor in T-SQL, but I wouldn't know if it is. Alternatively, newer versions of MS SQL Server give the facility to link in .NET code from any of the .NET languages using the Common Language Runtime (or CLR). I'm confident this could work for you, but I'm afraid my experience stops short of being much help along those lines.

Welcome to Bytes!
Aug 5 '10 #4
Jerry Winston
145 Expert 100+
I could tell you how to do this if I knew which table column1 belongs to. I think you're going for something like this (psudo-code):
Expand|Select|Wrap|Line Numbers
  1. WHILE B.lastrow = FALSE
  2.    IF B.column1 = NULL THEN
  3.       B.column1 = A.columnN(rowNumber)
  4.       rowNumber++
  5.    END IF 
  6. WEND
please be very specific about which field(column) is NULL and from where you would like to get data to update it.
Aug 10 '10 #5

Sign in to post your reply or Sign up for a free account.

Similar topics

1
by: Caroline | last post by:
I need to update a table by copying a column from another table (having the same structure, but on another database), from the record having the same primary key. 1 - What is the correct...
1
by: Alain Filiatrault | last post by:
HI, I have an SQL Server table with only 1 column. That column is an identity column. How can I insert a row in this table using SQL syntax? I tried insert into T_tableName () values ()...
3
by: Carmine | last post by:
I have to add a date column to a db2/zos table with a blob column. Can I rename the blob table to old, create a new table with the date column, then insert/select the data from the old table? ...
1
by: sho_nuff | last post by:
Hello all, Is it possible to have column specific context menus? so, if i have three columns containing different objects / info, i could have a context menu corresponding to each one? ...
2
by: GroZZleR | last post by:
Hey all, How do things like Windows Explorer and other applications get an empty column at the end of a data grid that stretches the entire width? Look at this picture:...
1
by: Random | last post by:
I don't understand why this error is happening when I try to load my xml into my DataSet. "Cannot add a nested relation or an element column to a table containing a SimpleContent column." Can...
6
by: Remaniak | last post by:
Hi all, I am using Access 2003. I am trying to insert a column "test" in "data table" right after the column "category". My code adds the column "test", but if I add the AFTER statement it...
1
by: Pydimarri Srinivas | last post by:
Hi All, I am trying to purge the data from a DB2 table having identity column defined usind DB2 utilitties. I am getting the following error "DSNU269I .............Field is invalid" "The...
3
by: madhavi123 | last post by:
Hi All, I have a to insert a set of rows into a table which is on some other server, and that table has an identity column which is also a primary key of that column. I am getting the error...
3
by: SANJINJIT | last post by:
Hi, I have a spreadsheet looks like this: QID C1 C2 C3 C4 %a %b %c %d 13123 b b b b 0% 100% 0% 0% 13124 d d d d 0% 0% 0% ...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.