Please start any new threads on our new
site at https://forums.sqlteam.com. We've got lots of great SQL Server
experts to answer whatever question you can come up with.
| Author |
Topic |
|
harlingtonthewizard
Constraint Violating Yak Guru
352 Posts |
Posted - 2010-11-25 : 02:32:55
|
| HI, I need the file path/location to be a variable. Any ideas what I am ding wrong below? ThanksUSE [VC]GO/****** Object: StoredProcedure [dbo].[SiteName_IncludeDeleted_RP] Script Date: 11/25/2010 17:06:28 ******/SET ANSI_NULLS ONGOSET QUOTED_IDENTIFIER ONGO-- =============================================-- Author: Steve Harlington-- Create date: <Create Date,,>-- Description: <Description,,>-- =============================================ALTER PROCEDURE [dbo].[SiteName_IncludeDeleted_RP]ASDeclare @Path nvarchar (200)Declare @sql1 nvarchar(max)SET @Path = (SELECT 'C:\Reports\Data\Customer_Site.MDB')Print @PathSET NOCOUNT ONDeclare @sql nvarchar(max)Select @sql=''Select @sql=@sql+ 'SELECT DISTINCT SiteDetails.SiteName, SiteDetails.SiteIDFROM '+name+'.dbo.SiteDetails ' from sys.databases where name='VC' or name like 'VCA%' Create table #t([SiteName] nvarchar(50), [SiteID] int)Insert into #tExec(@sql)--Print @sqlSelect DISTINCT [SiteName], [SiteID]from #tUnion AllSelect @sql1=''Select @sql1=@sql1+ 'SELECT SiteName, NULLFROM OPENROWSET(''Microsoft.Jet.OLEDB.4.0'',' + @Path + ';''admin'';'''',''Results'')AS Customer_Site'Drop table #tSET NOCOUNT OFFRETURNMsg 141, Level 15, State 1, Procedure SiteName_IncludeDeleted_RP, Line 0A SELECT statement that assigns a value to a variable must not be combined with data-retrieval operations. |
|
|
pk_bohra
Master Smack Fu Yak Hacker
1182 Posts |
Posted - 2010-11-25 : 03:44:03
|
| I executed the statement posted by you and it doesn't give me any error.Can you post the complete code of sp "SiteName_IncludeDeleted_RP" |
 |
|
|
harlingtonthewizard
Constraint Violating Yak Guru
352 Posts |
Posted - 2010-11-25 : 18:43:22
|
| I found this soulution;USE [VC]GO/****** Object: StoredProcedure [dbo].[SiteName_IncludeDeleted_RP] Script Date: 11/25/2010 17:06:28 ******/SET ANSI_NULLS ONGOSET QUOTED_IDENTIFIER ONGO-- =============================================-- Author: Steve Harlington-- Create date: <Create Date,,>-- Description: <Description,,>-- =============================================ALTER PROCEDURE [dbo].[SiteName_IncludeDeleted_RP]ASDeclare @Path nvarchar (200)Declare @sql1 nvarchar(max)SET @Path = (SELECT 'C:\Reports\Data\Customer_Site.MDB')Print @PathSET NOCOUNT ONDeclare @sql nvarchar(max)Select @sql=''Select @sql=@sql+ 'SELECT DISTINCT SiteDetails.SiteName, SiteDetails.SiteIDFROM '+name+'.dbo.SiteDetails ' from sys.databases where name='VC' or name like 'VCA%' Create table #t([SiteName] nvarchar(50), [SiteID] int)Insert into #tExec(@sql)Print @sqlSelect @sql1=''Select @sql1=@sql1+ 'SELECT SiteName, NULLFROM OPENROWSET(''Microsoft.Jet.OLEDB.4.0'',''' + @Path + ''';''admin'';'''',Results)AS Customer_Site'Insert into #tExec(@sql1)Print @sql1Select DISTINCT [SiteName], [SiteID]from #tORDER BY SiteNameDrop table #tSET NOCOUNT OFFRETURN |
 |
|
|
|
|
|
|
|