0

I am trying to select from a sql file (which is a query itselft) if I paste the query as text instead of openrowset it works, but i just cant figure out the syntax below, to keep the file independent and reusable

select * from openrowset(bulk 'F:\Movimenti.sql', formatfile='F:\Movimenti.sql' ) as Test 

due to error: Msg 9422, Level 16, State 48, Line 3 XML parsing: line 1, character 0, incorrect document syntax

UPDATE

I have found another way to achieve this

declare @SequelFile varchar(max) declare @sql varchar(max) select @SequelFile=BulkColumn from openrowset(bulk 'F:\Movimenti.sql',single_blob) x set @sql = ' select * from openquery([Navision], ''' + @SequelFile + ''' ) as Derivedtbl ' exec (@sql) 
4
  • This seems like a solution looking for a problem. Are you trying to load sql from an external file and run it? This might be easier in CMD mode Commented May 28, 2020 at 11:58
  • 1
    What are trying to achieve? An excerpt from the file might be useful to understand, but the goal is more important here. Also check XY problem. Commented May 28, 2020 at 11:59
  • See here for an easier way to run SQL files stackoverflow.com/questions/840831/… Commented May 28, 2020 at 12:01
  • I used to do it using VIEW, but the ssms view editor is difficult to read and edit the goal is to do nested queries , but i want to keep them divided because i need both levels, one level is grouped , the other one is not and so on.. so instead of having two queries with the same base, i want one query to build on top of other any other way to do this i welcomed... the purpose is BI and not a system, so I need to be able to change, add columns freely without having to change more than 1 query Commented May 28, 2020 at 12:14

0

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.