Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2000 Forums
 Transact-SQL (2000)
 Query problem

Author  Topic 

MariaM
Starting Member

17 Posts

Posted - 2008-02-06 : 03:07:46
Hi all !

I want to update one table with the contents of another table (which has the same variables). I do want to change the content of one of the variables at the same time though. Where this variable has the value of " " I want it to be null instead. Is it possible to do this in one statement ?

/M

SwePeso
Patron Saint of Lost Yaks

30421 Posts

Posted - 2008-02-06 : 03:27:42
UPDATE t1
SET t1.Col1 = NULLIF(t2.Col2, '') + '_Old'
FROM Table1 AS t1
INNER JOIN Table2 AS t2 ON t2.ColX = t1.ColBlue


E 12°55'05.25"
N 56°04'39.16"
Go to Top of Page

MariaM
Starting Member

17 Posts

Posted - 2008-02-06 : 04:19:52
Hi !
Thanks for the help. I didn't understand all of the query though. Do you think you could explain a little more ?

/M
Go to Top of Page

MariaM
Starting Member

17 Posts

Posted - 2008-02-06 : 04:25:32
Hi again !

I'm sorry , but I think I explained wrong what I want to do. I want to insert into a table not update.

/M
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2008-02-06 : 04:27:56
INSERT INTO DestinationTable (field1,Field2,...)
SELECT Field1,
NULLIF(Field2,''),
....other fields
FROM SourceTable

Field2 is the one you need to replace '' by NULL
Go to Top of Page
   

- Advertisement -