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.
| Author |
Topic |
|
fmardani
Constraint Violating Yak Guru
433 Posts |
Posted - 2007-02-26 : 04:45:00
|
| Hi,I have an insert query that has a select query to select the records to be inserted (See below).How do you make sure a null is entered into the field of a nullable field if there is no data to select for that field?insert into table1 Name, Lastname)select name, lastname from externalTablePlease note that if lastname in externalTable is empty, then I would like Lastname in Table1 to be inserted as null.Currently Table1.Lastname just inserts an empty value and NOT a null.Hope you know what I mean.Thanks |
|
|
khtan
In (Som, Ni, Yak)
17689 Posts |
Posted - 2007-02-26 : 04:47:31
|
[code]insert into table1 (Name, Lastname)select name, nullif(lastname, '') from externalTable[/code] KH |
 |
|
|
fmardani
Constraint Violating Yak Guru
433 Posts |
Posted - 2007-02-26 : 05:09:27
|
| Very good.Well done. |
 |
|
|
|
|
|