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)
 help with @var1 localvariable

Author  Topic 

podrik
Starting Member

3 Posts

Posted - 2004-09-10 : 10:32:20
What I'm doing wrong? Why doesn't "select * from @var1" work?

use pubs
Go
DECLARE @var1 varchar(50)
select @var1 = 'titles'
print @var1
Go
select * from @var1
Go

/Patrik

mwjdavidson
Aged Yak Warrior

735 Posts

Posted - 2004-09-10 : 10:35:52
It should be:

SELECT @var1

You could only do SELECT * FROM @var1 if @var1 was declared as a table variable.

Mark
Go to Top of Page

podrik
Starting Member

3 Posts

Posted - 2004-09-10 : 10:39:19
But how should I solve this then!
My problem is that I'm reading from another table which table I will insert a value!

/Patrik

quote:
Originally posted by mwjdavidson

It should be:

SELECT @var1

You could only do SELECT * FROM @var1 if @var1 was declared as a table variable.

Mark

Go to Top of Page

DustinMichaels
Constraint Violating Yak Guru

464 Posts

Posted - 2004-09-10 : 10:40:58
You have to use dynamic sql function like sp_executesql or EXECUTE(...) if you want to do something that you listed in your first post.

But it sounds like you don't even need to use dynamic sql to perform your task. Gives us more information about what your trying to do.


Dustin Michaels

Go to Top of Page

podrik
Starting Member

3 Posts

Posted - 2004-09-10 : 10:49:25
Thanks, you made my weekend much better know that I have solved this!

/Patrik

quote:
Originally posted by DustinMichaels

You have to use dynamic sql function like sp_executesql or EXECUTE(...) if you want to do something that you listed in your first post.

But it sounds like you don't even need to use dynamic sql to perform your task. Gives us more information about what your trying to do.


Dustin Michaels



Go to Top of Page
   

- Advertisement -