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 2005 Forums
 Transact-SQL (2005)
 Incorrect syntax near the keyword 'declare'.

Author  Topic 

ryoka012
Starting Member

20 Posts

Posted - 2012-08-16 : 00:35:49
Hi have this table function is below query is acceptable

create Function GetErrorCountOnTable(@Blno varchar(10),@Tablename varchar(50),@tableColumn varchar(50))

returns table
as
return
declare @mytable varchar(50)
set @mytable='Select * from'+ @Tablename + 'where'+ @tableColumn + '='+ @blno
exec(@mytable)

Error Message say's
Incorrect syntax near the keyword 'declare'.

khtan
In (Som, Ni, Yak)

17689 Posts

Posted - 2012-08-16 : 00:44:19
you can't use dynamic SQL in a function. Use Stored Procedure instead


KH
[spoiler]Time is always against us[/spoiler]

Go to Top of Page

ryoka012
Starting Member

20 Posts

Posted - 2012-08-16 : 00:45:46
Thanks for your prompt reply.
Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2012-08-16 : 10:47:04
Also why are passing object names as parameters?

Madhivanan

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

- Advertisement -