Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Way to update every column 2

Status
Not open for further replies.

seabaz2000

IS-IT--Management
Feb 24, 2006
79
IE
Hi,
I was just wondering is there any way to update every column in a given table something like this.
Code:
UPDATE #TempTableForData1
SET = " "
WHERE VALUE = NULL

This code above would aim to set every column that was null in the table to blank.
I hope I am explaining myself correctly.
Regards
 
Nope, you have to do each column one at a time.
Code:
update #TempTable1
SET Col1 = ''
WHERE Col1 is null

update #TempTable2
SET Col2 = ''
WHERE Col2 is null

...

Denny
MCSA (2003) / MCDBA (SQL 2000) / MCTS (SQL 2005) / MCITP Database Administrator (SQL 2005)

--Anything is possible. All it takes is a little research. (Me)
[noevil]
 
you could do it in 1 shot, but you still have to list them all out

update #TempTable1
SET Col1 = case col1 when null then '' else Col1 end,
SET Col2 = case col2 when null then '' else Col2 end
etc etc etc

next time consider using COALESCE on the insert
INSERT TempTable1 (col1 ,col12)
select coalesce(SomeVal,' '),coalesce(SomeVal2,' ')




Denis The SQL Menace
SQL blog:
 
Ditch the second set I gave you in the answer before
This is correct
Code:
update #TempTable1
SET Col1 = case col1 when null then '' else Col1 end,
Col2 = case col2 when null then '' else Col2 end
etc etc etc
another way
Code:
update #TempTable1
SET Col1 = coalesce(Col1 ,' '),
Col2 = coalesce(Col2 ,' '),
Col3 = coalesce(Col3 ,' ')
where Col1 is null
or  Col2 is null
or  Col3 is null

Denis The SQL Menace
SQL blog:
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top