View Poll Results: How do you copy from Table.field to table.field?

Voters
0. You may not vote on this poll
  • Help

    0 0%
  • Help

    0 0%
Results 1 to 4 of 4
  1. #1
    Join Date
    Nov 2002
    Location
    Florida
    Posts
    1

    Angry Unanswered: URGENT!! can you copy from one table to another?

    I need to write a script that can copy certain fields from one table to different fields in another table only if those fields are null.

    I have tried many different scripts, and maybe I have a brain Fart, but I can not figure this out.

    Please Help

  2. #2
    Join Date
    Nov 2002
    Posts
    24

    Post

    I hope that this demo puts you on the right track:

    create table #temp(adddd int)

    DECLARE @sql VARCHAR(1200) --lengthen if needed

    --insert into #temp
    set @sql =(SELECT 'ALTER TABLE #Temp ADD ' +

    CASE WHEN A1 IS NULL THEN 'A1 int NULL, ' ELSE '' END +

    CASE WHEN A2 IS NULL THEN 'A2 INT NULL, ' ELSE '' END +

    CASE WHEN A3 IS NULL THEN 'A3 INT NULL' ELSE '' END
    From testnull )

    PRINT @sql

    EXEC (@sql)

    select * from #temp
    ---drop table #temp
    TECMAN

  3. #3
    Join Date
    Nov 2002
    Posts
    24

    Post

    Oh and you will also need to create the testnull table, three columns then just put a value in one of them
    TECMAN

  4. #4
    Join Date
    Sep 2002
    Location
    Mancos, CO
    Posts
    73
    Here is a copy of some code that copies data from a table called Providers in one database to a table called vendors in another database where there is no existing entry in the vendors table.

    Hope this is what your looking for.

    Brent

    "INSERT INTO tblApVendor ( VendorID, Name, Addr1, Addr2, City, Region, PostalCode, Country, Ten99FormCode, Ten99FieldIndicator, Ten99ForeignAddrYN, SecondTINNotYN, VendorHoldYN, TempYN, TermsCode, DistCode, TaxableYN, CurrencyId, TaxGrpID, Ten99RecipientID ) " _
    & "SELECT tblProvider.ProviderID, tblProvider.ProviderName, tblProvider.MailAddress1, tblProvider.MailAddress2, tblProvider.MailCity, tblProvider.MailState, tblProvider.MailZipCode, ""USA"" AS Expr1, 1 AS Expr2, 7 AS Expr3, 0 AS Expr4, 0 AS Expr5, 0 AS Expr6, 0 AS Expr7, ""Net30"" AS Expr8, ""D001"" AS Expr9, 0 AS Expr10, ""DOLLAR"" AS Expr11, ""CA"" AS Expr12, tblProvider.TaxID " _
    & "FROM tblApVendor RIGHT OUTER JOIN tblProvider ON tblApVendor.VendorID = cstr(tblProvider.ProviderID) " _
    & "WHERE (((tblApVendor.VendorID) Is Null));"

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •