![]() | |
![]() |
| | Thread Tools | Display Modes |
#1
| |||
| |||
|
#2
| |||
| |||
|
|
-----Original Message----- I have a dts package with an execute sql task containing the code below. DTS refuses to let me use ? following the FROM. Tried placing the code w/in a variable and executing. Still no go. Suggestions anyone? Thanks much. SET @Tri_Select = 'SELECT firstname, middleinitial, lastname, address1,address2, city, state, zipcode, INTO ' + @TableName + ' FROM ' + ? + ' WHERE LTRIM(ISNULL(zip4,"")) <> "" AND lastname NOT LIKE "%,%" AND address1 <> "" AND filecode <> "6" AND donotmailcode = "N"' EXEC(@Tri_Select) . |
#3
| |||
| |||
|
|
I tried your code and this works. DECLARE @Tri_Select varchar(255) ,@TableName varchar(50) SELECT @TableName = 'TestTable' SET @Tri_Select = 'SELECT COL1, COL2, COL3, COL4 INTO ' + @TableName + ' FROM TableName' EXEC(@Tri_Select) You have an extra comma zipcode, and it is giving an error on the ISNULL(zip4,"")) - doen't like the double quotes. Hope this helps -----Original Message----- I have a dts package with an execute sql task containing the code below. DTS refuses to let me use ? following the FROM. Tried placing the code w/in a variable and executing. Still no go. Suggestions anyone? Thanks much. SET @Tri_Select = 'SELECT firstname, middleinitial, lastname, address1,address2, city, state, zipcode, INTO ' + @TableName + ' FROM ' + ? + ' WHERE LTRIM(ISNULL(zip4,"")) <> "" AND lastname NOT LIKE "%,%" AND address1 <> "" AND filecode <> "6" AND donotmailcode = "N"' EXEC(@Tri_Select) . |
#4
| |||
| |||
|
#5
| |||
| |||
|
|
Hey all, First, if anyone would care to help me out in a post a few lines down (subject is "can't use ? after FROM") I'd greatly appreciate it. But my main question is how does one dynamically set tablenames as parameters after certain commands (alter, from, drop, etc...)? Is it even possible? I know I can't be the first to hit this barrier... For instance, a line in my execute sql task reads "DROP TABLE @TableVar" Naturally, it doesn't work. Suggestions anyone? Thanks. |
#6
| |||
| |||
|
|
You would need to do this dynamically and the best article I can point you to is this one http://www.sommarskog.se/dynamic_sql.html -- -- Allan Mitchell MCSE,MCDBA, (Microsoft SQL Server MVP) www.SQLDTS.com - The site for all your DTS needs. www.konesans.com - Consultancy from the people who know "J McDermond" <nospam (AT) hotmail (DOT) com> wrote in message news:2m7ri4Fjra6oU1 (AT) uni-berlin (DOT) de... Hey all, First, if anyone would care to help me out in a post a few lines down (subject is "can't use ? after FROM") I'd greatly appreciate it. But my main question is how does one dynamically set tablenames as parameters after certain commands (alter, from, drop, etc...)? Is it even possible? I know I can't be the first to hit this barrier... For instance, a line in my execute sql task reads "DROP TABLE @TableVar" Naturally, it doesn't work. Suggestions anyone? Thanks. |
#7
| |||
| |||
|
![]() |
| Thread Tools | |
| Display Modes | |
| |