Showing posts with label calling. Show all posts
Showing posts with label calling. Show all posts

Tuesday, March 27, 2012

Creating View by calling Stored Proc

Hello all,
Is it possible to create a view by running the Stored Procedure in SQL Server 2000?
Thanks in advance,
VenugopalCreate Procedure CreateView
as

declare @.sql varchar(8000)

set @.sql =
'Create View MyView
as
select * from MyTable'

drop view MyView

exec(@.sql)

grant select on MyView to public

go|||Thanks for the reply. But what i was looking for what
Create View MyView As Exec SP1

Now i am able to do the same with OPenRowset, but the problem with that, it does allow the view to be schema bound without that i can't provide index to it.

Originally posted by mdhealy
Create Procedure CreateView
as

declare @.sql varchar(8000)

set @.sql =
'Create View MyView
as
select * from MyTable'

drop view MyView

exec(@.sql)

grant select on MyView to public

go|||Can't you just call the SP from the client?

Openrowset will create a new connection and can cause unexpected problems.|||Originally posted by nigelrivett
Can't you just call the SP from the client?

Openrowset will create a new connection and can cause unexpected problems.

No because requirement is that i have to write the query in access.
Currently there is a link table from Access to SQL Server. So if i create a view then there is no need for duplication and storing of data. Thats the reason i want to create the view with a SP.

Thanks

Friday, February 17, 2012

Creating FilePath for a BULK INSERT SP

Hi

I am creating an SP that will bulk insert data, the person calling the SP just needs to provide the file path and a number for the file and then the idea is i append this together to get the file to insert.

I have the SQL below which will not go past the BULK INSERT it is to do with my FilePath can anyone explain how I should be typing this?

Thanks very much

set ANSI_NULLS ON

set QUOTED_IDENTIFIER ON

go

CREATE PROCEDURE [dbo].[Get_DataFromFiles]

(

@.FileNumber VarCHAR(255),

@.FileID INT

)

AS

BEGIN

-- SET NOCOUNT ON added to prevent extra result sets from

-- interfering with SELECT statements.

SET NOCOUNT ON;

--

-- 1. Insert Tasks Table Data and obtain the new ID

--

BULK INSERT Tasks FROM @.FilePath + 'FileNumber' + @.FileID WITH (FIELDTERMINATOR = '<$%^&>')

declare @.sql varchar(8000)
select @.sql = 'BULK INSERT Tasks FROM ' + @.FilePath + 'FileNumber' + @.FileID + ' WITH (FIELDTERMINATOR = ''<$%^&>'')'

exec (@.sql)|||

No but I forgot to show the backslash in the code i posted should read

select @.sql = 'BULK INSERT Tasks FROM ' + @.FilePath + '\FileNumber' + @.FileID + ' WITH (FIELDTERMINATOR = ''<$%^&>'')'

I still get an error though which is

Incorrect syntax near '@.FilePath'

|||Thanks for your help didnt realise I had to build the statement then execute it rather than just build as needed. Much appreciated.