sql server - Output of SQL to be written on Excel In Standard path -
i trying save output of sql query excel , save in standard path. used openrowset write output.
but i'm getting error:
incorrect syntax near 'philips'.
please share valuable suggestions.
insert openrowset('microsoft.jet.oledb.4.0', 'excel 8.0;database=c:\testing.xls;', 'declare @vptvarchar(24) set @vpt= 'philips' declare @days int set @days = -30 select * #xtp1 (select distinct 'start' dtt, dateadd(d,@days,dateactioned) dt reports vpt = @vpt union select distinct 'change' dtt, dateactioned dt reports vpt = @vpt union select 'end' dtt, dateadd(dd, -1, datediff(dd, 0, getdate())) dt) [sheet1$]' thanks
you need add double quotes:
insert openrowset('microsoft.jet.oledb.4.0', 'excel 8.0;database=c:\testing.xls;', 'declare @vptvarchar(24) set @vpt= ''philips'' declare @days int set @days = -30 select * #xtp1 (select distinct ''start'' dtt, dateadd(d,@days,dateactioned) dt reports vpt = @vpt union select distinct ''change'' dtt, dateactioned dt reports vpt = @vpt union select ''end'' dtt, dateadd(dd, -1, datediff(dd, 0, getdate())) dt) [sheet1$]') that rid of syntax error, not looks @ query though
Comments
Post a Comment