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 Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Select NULL data to insert into another table

Status
Not open for further replies.

bmacbmac

IS-IT--Management
Jan 26, 2006
392
US
Hi. I am trying to get some data from server1 into server2. They are on two different networks and I was thinking of going this route....

Create an insert script out of my data from server1:

Code:
select 'insert into mytable (icountyid, ibasecountyid)' + ' values (' + convert(varchar(20), icountyid) + ',' + isnull(convert(varchar(20), ibasecountyid), '') + ')'
from my table

then I was just going to copy/paste the results from that query into server2:
Code:
insert into tblcounties (icountyid, ibasecountyid) values (15772,)
[code]

My problem is with NULL data.  The results from the query on server1 only leaves a blank spot in that field instead of actually using the word NULL... so my insert fails.

Is there another way I can do this?  I also tried coalesce but that doesn't work either.

Thanks!
 
you use
isnull(convert(varchar(20), ibasecountyid), '')
so , when ibasecountyid has null value , it's put : ''

you may be want to put:
isnull(convert(varchar(20), ibasecountyid), 'NULL')
 
Do you really want the literal 'NULL' in the table or do you want to see NULL when you display the results in the query window? If you want to see just NULL then using sabinUE's example change it to:

isnull(convert(varchar(20), ibasecountyid), NULL)
 
Since I am concatenating the results, the option using just NULL gave several lines in my results that said just said NULL (nothing else).

When using 'NULL' it created the lines just as I needed! Thanks for everyone's help!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top