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)
 MS SQL SERVER (EXEC)

Author  Topic 

AskSQLTeam
Ask SQLTeam Question

0 Posts

Posted - 2006-03-29 : 08:51:05
Arun writes "How do I get the result for the follwing dynamic querry.
I get the error @transno variable not declared

declare @sqlstring varchar(1024)
declare @transno char(15)
declare @Primary varchar(50)
declare @Tablename varchar(255)

set @sqlstring='select @transno = max(' + @Primary +')from ' + @Tablename

exec(@sqlstring)"

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2006-03-29 : 08:53:46
Refer this
http://www.nigelrivett.net/SQLTsql/sp_executesql.html

Madhivanan

Failing to plan is Planning to fail
Go to Top of Page

RickD
Slow But Sure Yak Herding Master

3608 Posts

Posted - 2006-03-29 : 08:54:15
set @sqlstring='select ' + @transno + ' = max(' + @Primary +')from ' + @Tablename
Go to Top of Page
   

- Advertisement -