April 15, 2008 at 7:19 am
Hi All,
Is there a way for creating a view from the stored procedure
Help is highly appreciated
April 15, 2008 at 7:31 am
do you want to create a view from within your stored procedure?
Or do you want to create a view that returns the same data as your stored procedure?
please expand your question a bit more
April 15, 2008 at 7:34 am
i want to create a view inside my stored procedure.if i give create view inside my stored procedure.it does not accepting
April 15, 2008 at 7:38 am
this is generally not a good idea. if your procs are altering the schema of your database, you are building on a shaky foundation indeed.
create view fails because it wants to be the first statement of the batch. I think the only way this will work is if you create the view in a dynamic sql call.
better not to do it at all though.
---------------------------------------
elsasoft.org
April 15, 2008 at 7:44 am
You can not do it directly with the CREATE VIEW command, but it can be done by using dynamic SQL
declare @sqlcode varchar(max)
select @sqlcode = 'create view vw_MyView as select * from MyTable'
exec (@sql)
But i would not recommend doing this at all as it is not good practice and alters the structure of your database.
Perhaps using temp tables or table variables would help you achieve your goal?
April 15, 2008 at 9:45 pm
Yes You people has good stuff, you are right. I was checking myself that is there a way which i might not known
Thanks guys
Viewing 6 posts - 1 through 5 (of 5 total)
You must be logged in to reply to this topic. Login to reply