You are here: Re: giving a proc database and table names as parameters « MsSQL Server « IT news, forums, messages
Re: giving a proc database and table names as parameters

Posted by Steve on 01/10/07 16:04

Dynamic SQL:
Books Online: Using sp_executesql
Web: http://www.sommarskog.se/dynamic_sql.html

Muhammed Al-Khoutani wrote:
> Hello!
>
> Is it possible to pass a stored procedure a parameter, say @table and
> use it as a table in the sql command?
> Finally i want a proc to copy tables from a database to another database.
>
> THERE IS MY CODE:
>
> CREATE PROCEDURE [user].[copytable]
> @dbSRC varchar(100),
> @dbTRGT varchar(100),
> @table varchar(100)
> AS
>
> BEGIN TRANSACTION FreeAndCopyTable
> TRUNCATE TABLE [@dbTRGT].admin.[@table]
> INSERT INTO [@dbTRGT].admin.[@table]
> SELECT *
> FROM [@dbSRC].admin.[@table]
>
> COMMIT TRANSACTION FreeAndCopyTable
> IF @@error <> 0 GOTO E_Copy_Fail
>
> E_Copy_Fail:
> ROLLBACK TRANSACTION FreeAndCopyTable
>
> GO
>
> thanks in advance,
> muh

 

Navigation:

[Reply to this message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация