Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2000 Forums
 SQL Server Development (2000)
 Table name as variable in select statement.

Author  Topic 

ravilobo
Master Smack Fu Yak Hacker

1184 Posts

Posted - 2002-09-20 : 02:26:22
Following query is not supported by SQL 2k.

declare @a varchar(50)
set @a='authors'
select * from @a

it give the error --"Must declare the variable '@a'"

(Where as oracle supports the above query .)

How handle this situation in Sql2k?

Thanks in advance ..



Merkin
Funky Drop Bear Fearing SQL Dude!

4970 Posts

Posted - 2002-09-20 : 02:39:05
Hi

You need some dynamic sql
http://www.sqlteam.com/SearchResults.asp?SearchTerms=dynamic+sql

Damian
Go to Top of Page

rihardh
Constraint Violating Yak Guru

307 Posts

Posted - 2002-09-20 : 05:34:54
It's really interesting that SQL statements that work in Oracle often don't work in MSSQL...

Go to Top of Page

Andraax
Aged Yak Warrior

790 Posts

Posted - 2002-09-20 : 06:32:22
Sure, but it's not ANSI SQL is it? I mean some things that work on SQL server doesn't work on Oracle and the other way around.

Go to Top of Page
   

- Advertisement -