• Want to receive the latest contracting news and advice straight to your inbox? Sign up to the ContractorUK newsletter here. Every sign up will also be entered into a draw to WIN £100 Amazon vouchers!

Oracle dynamic sql

Heeeeey. How am I the butt of the joke after what MS and LE posted? :laugh

Edit : Don't forget to look closely ;)

You still think I'm wrong? :confused:

You cannot use a variable name for a table directly.
You have to build a sql string and execute that.

Believe me.
 
You still think I'm wrong? :confused:

You cannot use a variable name for a table directly.
You have to build a sql string and execute that.

Believe me.

Or don't believe me - try it yourself.

SqlServer:

Code:
create table suityTest (suityString varchar(20));
insert into suityTest values ('value1')

declare @tablename varchar(20) = 'suityTest';
declare @value varchar(20) = 'value1';

-- this will work
select * from suityTest where suityString = @value;

-- this will work
declare @suitySQL varchar(max) = 
'select * from ' + @tablename  +
' where suityString = ''' + @value +'''';
exec (@suitySql)

-- this will fail
select * from @tablename where suityString = @value
 
MS, the article I linked to shows you to be wrong. Please read it.
 
Or to be fair you grasped the wrong end of the stick and started arguing the wrong point.
 
MS, the article I linked to shows you to be wrong. Please read it.

Your article says:

The string can also contain placeholders for bind arguments. However, you cannot use bind arguments to pass the names of schema objects to a dynamic SQL statement.
 
Example uses the order date to build the name of the table that should contain the data, and then incorporates that name into an INSERT statement.

Glad we are arguing the same point now. :)
 
Your article says:

The string can also contain placeholders for bind arguments. However, you cannot use bind arguments to pass the names of schema objects to a dynamic SQL statement.

Can't see that quote anywhere in the article. Then again I am bouncing around in the back of a taxi at present.
 
Glad we are arguing the same point now. :)

Ah, you mean the section headed "B. Executing a dynamically built string"

Exactly which bit of what I said are you disagreeing with?
 
Ah, you mean the section headed "B. Executing a dynamically built string"

Exactly which bit of what I said are you disagreeing with?

The bit where you say you can't pass a bind var as a table name.

Why are you quoting from an oracle article to support you SQL server argument? :confused:
 

Advertisers

Back
Top