You are here: Re: Go and goto in one sql script gives error label not declared « MsSQL Server « IT news, forums, messages
Re: Go and goto in one sql script gives error label not declared

Posted by dmarkle on 01/15/07 13:39

To be totally honest with you, I think the easiest/best way to solve
this would be to write a batch file that calls OSQL or SQLCMD against
the proper version of the file. Put your version-switching logic in
the batch file, and simply run OSQL on the appropriate files.

Some people execute their batches using sp_executesql, but it's really
messy and I don't really recommend it. Basically, using this method,
you'd be doing things like:

EXEC sp_executesql 'CREATE TABLE dbo.foo'
EXEC sp_executesql 'CREATE INDEX IX_xxx ON dbo.foo'
....

instead of:

CREATE TABLE dbo.foo
GO
CREATE INDEX IX_xxx ON dbo.foo
....

AFAIK, that's the only way to do what you want to do in 100% pure
T-SQL.

-Dave


BF wrote:
> Thanks for the quick respond.
>
> The solution is not quite what I was hoping for.
>
> For each new version I create an update script, We have an app which
> does that and there are lots of Go commands.
>
> I want to have one update script for all versions of the app so we have
> 2.00 to 2.01 to 2.02 to 2.03 etc.
>
> For each version I have a script and I want to lookup the version, if
> version is 2.03 I can start updating from 2.03 to 2.04 with the goto I
> can jump over all other updates because they are already done in the
> past.
>
> When I use different files I cannot easy control which files to
> execute, or I have to run them from the main script.
>
> Grtx Bob
>
> dmarkle schreef:
> > Here's the trick with "GO":
> >
> > It's not actually a part of the T-SQL language. It's a batch
> > separator. (Don't believe me? Try running "exec('GO')" in Query
> > Analyzer.)
> >
> > Think of it like this: Cut up your script into multiple files,
> > separated by the "GO" statement. Run each of these files individually,
> > but use the same connection. That's all "GO" does.
> >
> > So you need to remove the "GO" batch separators in between your
> > statements that need to be run in the same batch.
> >
> > -Dave Markle
> > http://www.markleconsulting.com/blog
> >

 

Navigation:

[Reply to this message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация