April 26, 2010 at 9:23 am
Hi,
I want to use a variable in a view.so i created a stored procedure and in that i have created a view .but, when i used the variable ina view and try to execute the procedure.
i am getting the error :
Must declare the scalar variable "@a".
April 26, 2010 at 9:32 am
the error tells what the issue is, but it might be a little new to you for debugging these kinds of issues.
to really help; we'd have to see the code for the stored procedure; anything else we did would just be syntax guessing, which might just confuse everyone even more.
Lowell
April 28, 2010 at 9:48 am
Try using dynamic SQL to concatinate the variable into your view. I assume you do not want the variable to be created as part of the view rather whatever the variables value is to be created in the view.
April 29, 2010 at 6:58 am
As Lowell said, providing the code will allow us to help you refactor it or tell you a better way to go... but barring that:
You can't use variables in a view. Instead of putting the 'create view' inside of a stored procedure, just use the variables in the stored procedure and do the select and don't create the view at all.
April 30, 2010 at 10:54 pm
I would try creating a table function instead of a view since you want to pass parameters; there are some limitations on what can be done in a function: http://msdn.microsoft.com/en-us/library/ms186755.aspx
April 30, 2010 at 11:27 pm
itskumar2004 (4/26/2010)
Hi,I want to use a variable in a view.so i created a stored procedure and in that i have created a view .but, when i used the variable ina view and try to execute the procedure.
i am getting the error :
Must declare the scalar variable "@a".
Ummm.... why don't you just do a SELECT from the view with the correct WHERE clause? You don't need to add a variable to a view...
--Jeff Moden
Change is inevitable... Change for the better is not.
Viewing 6 posts - 1 through 5 (of 5 total)
You must be logged in to reply to this topic. Login to reply