Click here to Skip to main content
15,897,371 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have stored procedure and needs to declare servername. When my stored procedure saved I have an error message "Incorrect syntax near '.'." This is because SELECT * FROM @servername.[database].dbo.[tablename]. How do write the correct query using @servername?
Posted

From your post it seems that @ServerName is local procedure variable and you are trying to generate your query dynamically and so you need to execute it dynamically too.There's special system stored procedure called sp_executesql which could do that for you.
 
Share this answer
 
Unfortunately I needed to execute in crystal report that the database is set to stored procedure.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900