update a tableon other db from other db 's

  • CREATE PROCEDURE proc_lastSale AS

    set ANSI_NULLS ON

    set QUOTED_IDENTIFIER ON

    declare csr_db cursor for

    select [name] from master..sysdatabases

    where [name] LIKE 'Shop%'

    declare @cmd varchar(1000)

    declare @dbs varchar(250)

    DECLARE @Tmp VARCHAR(250)

    open csr_db

    fetch next from csr_db into @dbs

    while @@fetch_status = 0

    BEGIN

    SELECT @Tmp = MAX(lastSale) FROM @dbs.dbo.Tb_offer

    SET @cmd = 'update OFFICE.dbo.LOG_Shops set lastSale = '''+ @Tmp +'''

    where db_name ='''+ @dbs +''''

    exec(@cmd)

    fetch next from csr_db into @dbs

    END

    close csr_db

    deallocate csr_db

  • What is the question here?

  • testing, before you even begin to reply, please read and fully comprehend the following link. We'll make your life easier if you make our life easier.

    http://www.sqlservercentral.com/articles/Best+Practices/61537/

    -- You can't be late until you show up.

  • I am searching an solution for these problem:

    I want to update a log table with information that I get from other databases.

    for examples

    I have 4 databases with the name shopBrussels,shopAntwerpen,shopGent,shopLiege

    each database has the same structure (same name of tables) sales table, offer table, products table and so on

    from each database I want to get the lastSaledate from table sales , I must put these values at a log table

    by the way thx,

    Jo

Viewing 4 posts - 1 through 3 (of 3 total)

You must be logged in to reply to this topic. Login to reply