views:

14

answers:

1

Create Procedure USP_UploadTraining
@filePath varchar(100) AS

BEGIN

Insert into Training_TRNS (EmpName,EmpJobFunction,EmpRegion,SpeCourse_ID,status,DueDate)
select F2+' '+F3 as Name,F4 as JobFunction, F6 as EVPRegion, F7 as CourseTitle,F8 as Status, convert(varchar,F9,101) as DateAcq
FROM OPENROWSET('Microsoft.Jet.OLEDB.4.0',
'Excel 8.0;Database='@filePath'', 'SELECT * FROM [Sheet1$]')
where f2!='First Name'

END

it's give syntax error can anyone this modify.

A: 

you need to use Sp_ExecuteSql for this because you have to replace @filePath when you run the query

Try following query

 Create Procedure USP_UploadTraining
@filePath varchar(100) AS

BEGIN
DECLARE @ParmDefinition nvarchar(500);
SET @ParmDefinition = N'@filePath1 varchar(100)';
DECLARE @SQLString nvarchar(max);

SET  @SQLString='Insert into Training_TRNS (EmpName,EmpJobFunction,EmpRegion,SpeCourse_ID,status,DueDate)
select F2+'' ''+F3 as Name,F4 as JobFunction, F6 as EVPRegion, F7 as CourseTitle,F8 as Status, convert(varchar,F9,101) as DateAcq
FROM OPENROWSET(''Microsoft.Jet.OLEDB.4.0'',
''Excel 8.0;Database= @filePath'', ''SELECT * FROM [Sheet1$]'')
where f2!=''First Name'''


EXECUTE sp_executesql
     @SQLString
    ,@ParmDefinition
    ,@filePath1 = @filePath
    ;


END
Pranay Rana
Procedure expects parameter '@statement' of type 'ntext/nchar/nvarchar'.Through Error
Manoj Wadhwani
there is no syntax error at my end
Pranay Rana
Thanks for you help and your code is right, but when i m executing this code then it through this error. If you can solve it then plz try .....It very urgent.I appreciate your help.
Manoj Wadhwani
query is updated now check it now
Pranay Rana
Thanks Pranay I appreciate your help .......You dont know how this code is too important for me toady.
Manoj Wadhwani