dbTalk Databases Forums  

can't use ? after FROM

microsoft.public.sqlserver.dts microsoft.public.sqlserver.dts


Discuss can't use ? after FROM in the microsoft.public.sqlserver.dts forum.



Reply
 
Thread Tools Display Modes
  #1  
Old   
J McDermond
 
Posts: n/a

Default can't use ? after FROM - 07-20-2004 , 02:15 PM






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)



Reply With Quote
  #2  
Old   
Mark
 
Posts: n/a

Default can't use ? after FROM - 07-20-2004 , 03:34 PM






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

Quote:
-----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)


.


Reply With Quote
  #3  
Old   
J McDermond
 
Posts: n/a

Default Re: can't use ? after FROM - 07-21-2004 , 09:55 AM



Thanks for the assistance Mark, but I'm still generating errors.
Error I get when I try your method is:
"Cannot use empty object or column names. Use a single space if necessary."

You would think MS would make it easy to pass a tablename in as a
variable...

"Mark" <anonymous (AT) discussions (DOT) microsoft.com> wrote

Quote:
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)


.




Reply With Quote
  #4  
Old   
J McDermond
 
Posts: n/a

Default Parameters after "FROM" & "DROP" - 07-21-2004 , 01:38 PM



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.



Reply With Quote
  #5  
Old   
Allan Mitchell
 
Posts: n/a

Default Re: Parameters after "FROM" & "DROP" - 07-21-2004 , 01:55 PM



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

Quote:
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.





Reply With Quote
  #6  
Old   
J McDermond
 
Posts: n/a

Default Re: Parameters after "FROM" & "DROP" - 07-21-2004 , 03:19 PM



Thanks for the link Al. I solved my issues...sort of...

My sql runs fine in query analyzer, both parses and executes with no
problems. However, when placed in my execute sql task, it shoots up this
enigmatic error:
Error Source: Microsoft OLE DB Provider for SQL Server
Error Description: Could not find prepared statement with handle 1.

Anyone else ever encounter this error?

"Allan Mitchell" <allan (AT) no-spam (DOT) sqldts.com> wrote

Quote:
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.







Reply With Quote
  #7  
Old   
Mingqing Cheng [MSFT]
 
Posts: n/a

Default Re: Parameters after "FROM" & "DROP" - 07-21-2004 , 09:58 PM



Hi J McDermond,

This error seems strange, Have you upgraed to SQL Server SP3a? How about trying a restart
of machine? It is highly recommand if you could make all latest service pack done on you box,
including for Windows, for SQL Server and for MDAC, and then make a restart to see whether
this issue still exists. If so, would you please so kind as to paste so detailed of your codes in
task so that it might be possible for me to reproduce it on my box.

Thank you for your patience and cooperation. If you have any questions or concerns, don't
hesitate to let me know. We are here to be of assistance!


Sincerely yours,

Mingqing Cheng
Microsoft Developer Community Support
---------------------------------------------------------------
Introduction to Yukon! - http://www.microsoft.com/sql/yukon
This posting is provided "as is" with no warranties and confers no rights.
Please reply to newsgroups only, many thanks!







Reply With Quote
Reply




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.3
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.