|
-
May 16th, 2001, 09:11 AM
#1
SQL Stored Procedure Problem
Hi
I have a question regarding SLQ variables. I am setting the variable through a cursor. When I check the syntax of this SQL, it says that I need to declare @TableName on the line that says
select @eid = eid from @tableName . Is it not possible to do this? I know that I've used such variable in a where clause. Is it because I am using it in a from clause? Do I need some other kind of syntax to do this?
declare @elementClassId int,
@eid eid,
@className varchar(32),
@tableName varchar(32),
@aid eid,
@attributeName varchar(32)
declare classCursor cursor for
select classId, TableName from tmbElementClasses where classAttributes = 3
order by TableName
open classCursor
fetch classCursor into @elementClassId, @tableName
while (@@fetch_status = 0)
BEGIN
if( @elementClassId is not NULL and @tableName is not NULL )
begin
select @eid = eid from @tableName
end
fetch classCursor into @elementClassId, @tableName
END
close classCursor
deallocate classCursor
Thanks in advance
-
May 16th, 2001, 09:25 AM
#2
Re: SQL Stored Procedure Problem
It is not possible to substitute a variable for a table or view name in a select statement, sorry.
The best workaround is to have:
If @tablename = TCLMDETS
Select @eid = eid FROM TCLMDETS
Else
Select @eid = eid FROM TCLMTRXN
or as many IFs as you have tables.
HTH,
D
-------------------------------------------------
Ex. Datis: Duncan Jones
Merrion Computing Ltd
http://www.merrioncomputing.com
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|