Showing posts with label sqlcmd. Show all posts
Showing posts with label sqlcmd. Show all posts

Saturday, February 25, 2012

Programmatic access to the code SQLCMD uses to parse sql into batches

Hi,

I am thinking of writing a C# Windows app to iterate a set of sql scripts and submit them to SQL Server. Many scripts have "go" as a batch delimiter. I could probably figure out a regular expression to parse for that delimiter, but it seems tricky (need to exclude 'go', -- go, /* go */, etc). Obviously SQLCMD and Management Studio have a way to do this. I was wondering if that's exposed in an API anywhere. I looked into the SMO object model, but I couldn't find it.

Thanks much,

Mike

Hi,

thats no mafic, just use the SET PARSEONLY statement before your statements to check.

HTH, Jens Suessmeyer.


http://www.sqlserver2005.de

|||

As far as I can tell "set parseonly on" just checks the syntax. I want to get back a collection of strings to submit, each one a proper batch. Eg:

select 'Inside quotes, go or " go " or '' go '' is not a delimiter ' as go -- not go here

select 'Second go '

go

select 'Another batch here /* go */ go '

go

In query analyzer or management studio this appropriately returns 3 result sets, presumably executed as 2 batches. I would like to identify the first 2 lines as one batch, and the second select as another batch.

Mike