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!

Importing to table from another table 1

Status
Not open for further replies.

Halliarse

IS-IT--Management
Jan 8, 2007
213
GB
Hi

I'm using MS MSQL 2012.

I'm hoping this should be relatively straightforward and just an issue due to my SQL inexperience!!!

I have 2 versions of the same table on different databases, however,the 2nd table has additional columns. One of these additional columns does not allow nulls which is where my problem occurs!

I'm running the following script

INSERT into CTS..SL_Accounts([CUCODE]
,[CUNAME]
,[CUADDRESS]
,[CUPOSTCODE]
,[CUPHONE]
,[CUPHONE2]
,[CUFAX]
,[CUPROSCODE]
,[CUCONTACT]
,[CU_MULTI_CURR]
,[CUSALUTE]
,[CU_PRO_CONDATE]
,[CU_EXPORT_CODE]
,[CU_COUNTRY_CODE]
,[CU_VAT_REG_NO]
,[CU_EC_DELIVERY]
,[CU_EC_T_NATURE]
,[CU_EC_T_MODE]
,[CUBALANCE]
,[CUBALANCE_C]
,[CUAGED_1]
,[CUAGED_2]
,[CUAGED_3]
,[CUAGED_4]
,[CUAGED_UNALLOC]
,[CUSORT]
,[CUUSER1]
,[CUUSER2]
,[CUUSER3]
,[CUUSED]
,[CUTURNOVERPTD]
,[CUTURNOVR_L1]
,[CUTURNOVR_L2]
,[CUTURNOVR_L3]
,[CUTURNOVR_L4]
,[CUTURNOVR_L5]
,[CUTURNOVR_L6]
,[CUTURNOVR_L7]
,[CUTURNOVR_L8]
,[CUTURNOVR_L9]
,[CUTURNOVR_L10]
,[CUTURNOVR_L11]
,[CUTURNOVR_L12]
,[CUTURNOVR_L13]
,[CUTURNOVR_C1]
,[CUTURNOVR_C2]
,[CUTURNOVR_C3]
,[CUTURNOVR_C4]
,[CUTURNOVR_C5]
,[CUTURNOVR_C6]
,[CUTURNOVR_C7]
,[CUTURNOVR_C8]
,[CUTURNOVR_C9]
,[CUTURNOVR_C10]
,[C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,[CU_ADDRESS_USER2]
,[CU_EMAIL]
,[CU_WEB_PASSWORD]
,[CU_CURRENCY_CHANGED]
,[CU_SOURCE]
,[CU_ACCOUNT_TYPE]
,[CU_DOC_DESTINATION]
,[CU_COUNTRY]
,[CU_DO_NOT_USE]
,[CU_CREDIT_CONTROLLER]
,[CU_TERMS_LINK]
,[CU_CURR_CREDIT_LIMIT]
,[CU_ANT_DAYS_FROM_DATES_OPT]
,[CU_PAYMENT_PROMISED]
,[CU_PAYMENT_PROMISED_DATE]
,[CU_CUSTOM_TERMS_TEMPLATE]
,[CU_PAYMENT_PROMISED_CURRENCY]
,[CU_COMPANY_REG_NUMBER])
select [CUCODE]
,[CUNAME]
,[CUADDRESS]
,[CUPOSTCODE]
,[CUPHONE]
,[CUPHONE2]
,[CUFAX]
,[CUPROSCODE]
,[CUCONTACT]
,[CU_MULTI_CURR]
,[CUSALUTE]
,[CU_PRO_CONDATE]
,[CU_EXPORT_CODE]
,[CU_COUNTRY_CODE]
,[CU_VAT_REG_NO]
,[CU_EC_DELIVERY]
,[CU_EC_T_NATURE]
,[CU_EC_T_MODE]
,[CUBALANCE]
,[CUBALANCE_C]
,[CUAGED_1]
,[CUAGED_2]
,[CUAGED_3]
,[CUAGED_4]
,[CUAGED_UNALLOC]
,[CUSORT]
,[CUUSER1]
,[CUUSER2]
,[CUUSER3]
,[CUUSED]
,[CUTURNOVERPTD]
,[CUTURNOVR_L1]
,[CUTURNOVR_L2]
,[CUTURNOVR_L3]
,[CUTURNOVR_L4]
,[CUTURNOVR_L5]
,[CUTURNOVR_L6]
,[CUTURNOVR_L7]
,[CUTURNOVR_L8]
,[CUTURNOVR_L9]
,[CUTURNOVR_L10]
,[CUTURNOVR_L11]
,[CUTURNOVR_L12]
,[CUTURNOVR_L13]
,[CUTURNOVR_C1]
,[CUTURNOVR_C2]
,[CUTURNOVR_C3]
,[CUTURNOVR_C4]
,[CUTURNOVR_C5]
,[CUTURNOVR_C6]
,[CUTURNOVR_C7]
,[C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
,[CU_PRIMARY]
,[CU_DEALERCODE]
,[CU_ADDRESS_USER1]
,[CU_ADDRESS_USER2]
,[CU_EMAIL]
,[CU_WEB_PASSWORD]
,[CU_CURRENCY_CHANGED]
,[CU_SOURCE]
,[CU_ACCOUNT_TYPE]
,[CU_DOC_DESTINATION]
,[CU_COUNTRY]
,[CU_DO_NOT_USE]
,[CU_CREDIT_CONTROLLER]
,[CU_TERMS_LINK]
,[CU_CURR_CREDIT_LIMIT]
,[CU_ANT_DAYS_FROM_DATES_OPT]
,[CU_PAYMENT_PROMISED]
,[CU_PAYMENT_PROMISED_DATE]
,[CU_CUSTOM_TERMS_TEMPLATE]
,[CU_PAYMENT_PROMISED_CURRENCY]
,[CU_COMPANY_REG_NUMBER] from DLA..SL_ACCOUNTS INNER JOIN
DLA..SL_ACCOUNTS2 ON DLA..SL_ACCOUNTS.CU_PRIMARY = DLA..SL_ACCOUNTS2.CU_PRIMARY_2
where CUSORT <> 'OBSOLETE' and CU_USRCHAR2 = 'SERVICE' and (CU_DATE_INV>='01/11/2011' or CU_DATE_PAY>='01/11/2011')

The CTS version of the database has the additional column called Direc_Debit_Type...how do I get around this on the Insert statement?

Thanks in advance

Steve
 
This one is probably a no-brainer for the sql guru's here, but I am a bit of a novice and do know how to do this....

I need to create a query that will pull fields from another db's table but also take 3 fields and combine them into one.. for example, I need to take 4 fields: "address", "City", "state", and "zip" and combine them into one field and insert a comma between address and city and between city and state. and a space between state and zip.

can anybody tell me how I can go about this?

I need the query to either create a table from this or update a table from this.... thank you in advance for the help..
 
I apologize for that reply... I thought I was submitting a new post to this forum...
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top