I'm trying to perform some upgrade maintenance on our database. I need to move 3 columns of data from all rows of one table and insert that data as new rows in a new table.
INSERT INTO [dbo].[SnmpSettings]([NetworkDiscoveryId], [RoCommunities], [RwCommunities])
SELECT id, Ro_Community, RW_Communities
FROM [dbo].[Network_Discovery]
The above code would work fine, but Ro_Community and RW_Communities allow NULL where as RoCommunities and RwCommunities do not allow NULL. How should I convert NULLs to the empty string and then insert into my new table?
EDIT:
INSERT INTO [dbo].[SnmpSettings]([NetworkDiscoveryId], [RoCommunities], [RwCommunities])
SELECT id, Ro_Community, RW_Communities
ISNULL(Ro_Community,'')
FROM [dbo].[Network_Discovery]
Msg 102, Level 15, State 1, Line 27
Incorrect syntax near 'Ro_Community'.
SELECT ISNULL(Ro_Community, '')
or
SELECT COALESCE(Ro_Community, '')
Note: COALESCE is supported since SQL Server 2005. It is part of the ANSI-92 SQL standard, so many suggest it's preferred over ISNULL. However there are also reports that it is a bit slower.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With