Hi,
I'd like a really simple way of making a replica of a table. The thing is i'd like the table name to be a variable. The following code doesn't work, any ideas??
Thanks in advance,
Alph
CREATE Procedure Test
@.vMonth as varchar(3)
As
SELECT tbl_Targets.* INTO @.vmonth
FROM tbl_Targets;
GOLook up sp_executesql and EXECUTE in the SQL Books Online.
Showing posts with label variable. Show all posts
Showing posts with label variable. Show all posts
Thursday, March 22, 2012
Thursday, March 8, 2012
Copying data from another DB on server problem
What iam trying to do is put the table name from one db into a variable and another one into another variable and pass them into my statement basicaly trying to bulk copy data from one table in a db and insert it into another db on the same server based on a condition
if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[ClientComment]')
and OBJECTPROPERTY(id, N'IsUserTable') = 1)
Declare @.BDFR varchar(20), @.BDTO varchar(20), @.EQID varchar(20)
set @.BDFR = 'Commander' + '.dbo.' + 'ClientComment'
set @.BDTO = 'Test_Commander' + '.dbo.' + 'ClientComment'
set @.EQID = '80_300_005'
insert into @.BDTO
select * from @.BDFR where Eqid = @.EQIDplz help .......|||You need to use dynamic SQL to do what you're envisioning.
Beware that dynamic SQL breaks most of the commonly accepted rules about security/permissions/etc because of the way that it works... The dynamic SQL is permission checked based on the user that is running the SQL.
With that said, I'd use something like:DECLARE @.BDFR varchar(20), @.BDTO varchar(20), @.EQID varchar(20)
SET @.BDFR = 'Commander' + '.dbo.' + 'ClientComment'
SET @.BDTO = 'Test_Commander' + '.dbo.' + 'ClientComment'
SET @.EQID = '80_300_005'
EXECUTE ('insert into ' + @.BDTO
+ ' select * from ' + @.BDFR + ' where Eqid = @.EQID')-PatP
if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[ClientComment]')
and OBJECTPROPERTY(id, N'IsUserTable') = 1)
Declare @.BDFR varchar(20), @.BDTO varchar(20), @.EQID varchar(20)
set @.BDFR = 'Commander' + '.dbo.' + 'ClientComment'
set @.BDTO = 'Test_Commander' + '.dbo.' + 'ClientComment'
set @.EQID = '80_300_005'
insert into @.BDTO
select * from @.BDFR where Eqid = @.EQIDplz help .......|||You need to use dynamic SQL to do what you're envisioning.
Beware that dynamic SQL breaks most of the commonly accepted rules about security/permissions/etc because of the way that it works... The dynamic SQL is permission checked based on the user that is running the SQL.
With that said, I'd use something like:DECLARE @.BDFR varchar(20), @.BDTO varchar(20), @.EQID varchar(20)
SET @.BDFR = 'Commander' + '.dbo.' + 'ClientComment'
SET @.BDTO = 'Test_Commander' + '.dbo.' + 'ClientComment'
SET @.EQID = '80_300_005'
EXECUTE ('insert into ' + @.BDTO
+ ' select * from ' + @.BDFR + ' where Eqid = @.EQID')-PatP
Saturday, February 25, 2012
Copying a column to a SSIS package variable
I need to use a value retrieved in one data flow in the second data flow. What's the best way to do this?
How do I copy the column retrieved to a variable so I can use that variable in the second data flow?
Data Flow implies multiple rows, which doesn't naturally fit with a single variable.
Normally I would be using an Exec SQL Task to populate a variable from a table. You could use a Script Component in the data flow, or perhaps the Recordset Destination if there are several rows.
If reading just one value/line from a file for example, then I'd just use the Script Task.
Subscribe to:
Posts (Atom)