dbTalk Databases Forums  

About PRINT and other SQLCMD questions

microsoft.public.sqlserver.tools microsoft.public.sqlserver.tools


Discuss About PRINT and other SQLCMD questions in the microsoft.public.sqlserver.tools forum.



Reply
 
Thread Tools Display Modes
  #31  
Old   
Erland Sommarskog
 
Posts: n/a

Default Re: About PRINT and other SQLCMD questions - 06-03-2008 , 04:59 PM






.....DotNet4Ever.... (hate.spam (AT) nowhere (DOT) com) writes:
Quote:
Just another question on this topic...

Assuming my SQL script is used with SQLCMD and I use it to "source" other
scripts such as this:

BEGIN TRY
PRINT 'Installing Common'
BEGIN TRANSACTION T1
:r Create\Common.SQL -- Does multiple INSERT
PRINT 'Installing Add-on'
IF @@TranCount > 0
BEGIN
:r Create\AddOn.SQL -- Does multiple INSERT
COMMIT TRANSACTION T1
END
END TRY
BEGIN CATCH
ROLLBACK TRANSACTION T1
END CATCH
GO

Then my question is, would the approach you mentioned with @@transcount
work here as well? or does it get "broken" by the fact that two child
scripts (:r) are sourced?
Well, that depends on what it is those files. If there are any GO
in them, you will get a syntax error for the BEGIN TRY without
a matching END TRY. Unless there is one in the file you include.

But if there are no GO in the file, this should work fine.


--
Erland Sommarskog, SQL Server MVP, esquel (AT) sommarskog (DOT) se

Books Online for SQL Server 2005 at
http://www.microsoft.com/technet/pro...ads/books.mspx
Books Online for SQL Server 2000 at
http://www.microsoft.com/sql/prodinf...ons/books.mspx


Reply With Quote
  #32  
Old   
Erland Sommarskog
 
Posts: n/a

Default Re: About PRINT and other SQLCMD questions - 06-03-2008 , 04:59 PM






.....DotNet4Ever.... (hate.spam (AT) nowhere (DOT) com) writes:
Quote:
Just another question on this topic...

Assuming my SQL script is used with SQLCMD and I use it to "source" other
scripts such as this:

BEGIN TRY
PRINT 'Installing Common'
BEGIN TRANSACTION T1
:r Create\Common.SQL -- Does multiple INSERT
PRINT 'Installing Add-on'
IF @@TranCount > 0
BEGIN
:r Create\AddOn.SQL -- Does multiple INSERT
COMMIT TRANSACTION T1
END
END TRY
BEGIN CATCH
ROLLBACK TRANSACTION T1
END CATCH
GO

Then my question is, would the approach you mentioned with @@transcount
work here as well? or does it get "broken" by the fact that two child
scripts (:r) are sourced?
Well, that depends on what it is those files. If there are any GO
in them, you will get a syntax error for the BEGIN TRY without
a matching END TRY. Unless there is one in the file you include.

But if there are no GO in the file, this should work fine.


--
Erland Sommarskog, SQL Server MVP, esquel (AT) sommarskog (DOT) se

Books Online for SQL Server 2005 at
http://www.microsoft.com/technet/pro...ads/books.mspx
Books Online for SQL Server 2000 at
http://www.microsoft.com/sql/prodinf...ons/books.mspx


Reply With Quote
  #33  
Old   
Erland Sommarskog
 
Posts: n/a

Default Re: About PRINT and other SQLCMD questions - 06-03-2008 , 04:59 PM



.....DotNet4Ever.... (hate.spam (AT) nowhere (DOT) com) writes:
Quote:
Just another question on this topic...

Assuming my SQL script is used with SQLCMD and I use it to "source" other
scripts such as this:

BEGIN TRY
PRINT 'Installing Common'
BEGIN TRANSACTION T1
:r Create\Common.SQL -- Does multiple INSERT
PRINT 'Installing Add-on'
IF @@TranCount > 0
BEGIN
:r Create\AddOn.SQL -- Does multiple INSERT
COMMIT TRANSACTION T1
END
END TRY
BEGIN CATCH
ROLLBACK TRANSACTION T1
END CATCH
GO

Then my question is, would the approach you mentioned with @@transcount
work here as well? or does it get "broken" by the fact that two child
scripts (:r) are sourced?
Well, that depends on what it is those files. If there are any GO
in them, you will get a syntax error for the BEGIN TRY without
a matching END TRY. Unless there is one in the file you include.

But if there are no GO in the file, this should work fine.


--
Erland Sommarskog, SQL Server MVP, esquel (AT) sommarskog (DOT) se

Books Online for SQL Server 2005 at
http://www.microsoft.com/technet/pro...ads/books.mspx
Books Online for SQL Server 2000 at
http://www.microsoft.com/sql/prodinf...ons/books.mspx


Reply With Quote
  #34  
Old   
Erland Sommarskog
 
Posts: n/a

Default Re: About PRINT and other SQLCMD questions - 06-03-2008 , 04:59 PM



.....DotNet4Ever.... (hate.spam (AT) nowhere (DOT) com) writes:
Quote:
Just another question on this topic...

Assuming my SQL script is used with SQLCMD and I use it to "source" other
scripts such as this:

BEGIN TRY
PRINT 'Installing Common'
BEGIN TRANSACTION T1
:r Create\Common.SQL -- Does multiple INSERT
PRINT 'Installing Add-on'
IF @@TranCount > 0
BEGIN
:r Create\AddOn.SQL -- Does multiple INSERT
COMMIT TRANSACTION T1
END
END TRY
BEGIN CATCH
ROLLBACK TRANSACTION T1
END CATCH
GO

Then my question is, would the approach you mentioned with @@transcount
work here as well? or does it get "broken" by the fact that two child
scripts (:r) are sourced?
Well, that depends on what it is those files. If there are any GO
in them, you will get a syntax error for the BEGIN TRY without
a matching END TRY. Unless there is one in the file you include.

But if there are no GO in the file, this should work fine.


--
Erland Sommarskog, SQL Server MVP, esquel (AT) sommarskog (DOT) se

Books Online for SQL Server 2005 at
http://www.microsoft.com/technet/pro...ads/books.mspx
Books Online for SQL Server 2000 at
http://www.microsoft.com/sql/prodinf...ons/books.mspx


Reply With Quote
  #35  
Old   
Erland Sommarskog
 
Posts: n/a

Default Re: About PRINT and other SQLCMD questions - 06-03-2008 , 04:59 PM



.....DotNet4Ever.... (hate.spam (AT) nowhere (DOT) com) writes:
Quote:
Just another question on this topic...

Assuming my SQL script is used with SQLCMD and I use it to "source" other
scripts such as this:

BEGIN TRY
PRINT 'Installing Common'
BEGIN TRANSACTION T1
:r Create\Common.SQL -- Does multiple INSERT
PRINT 'Installing Add-on'
IF @@TranCount > 0
BEGIN
:r Create\AddOn.SQL -- Does multiple INSERT
COMMIT TRANSACTION T1
END
END TRY
BEGIN CATCH
ROLLBACK TRANSACTION T1
END CATCH
GO

Then my question is, would the approach you mentioned with @@transcount
work here as well? or does it get "broken" by the fact that two child
scripts (:r) are sourced?
Well, that depends on what it is those files. If there are any GO
in them, you will get a syntax error for the BEGIN TRY without
a matching END TRY. Unless there is one in the file you include.

But if there are no GO in the file, this should work fine.


--
Erland Sommarskog, SQL Server MVP, esquel (AT) sommarskog (DOT) se

Books Online for SQL Server 2005 at
http://www.microsoft.com/technet/pro...ads/books.mspx
Books Online for SQL Server 2000 at
http://www.microsoft.com/sql/prodinf...ons/books.mspx


Reply With Quote
  #36  
Old   
Erland Sommarskog
 
Posts: n/a

Default Re: About PRINT and other SQLCMD questions - 06-03-2008 , 04:59 PM



.....DotNet4Ever.... (hate.spam (AT) nowhere (DOT) com) writes:
Quote:
Just another question on this topic...

Assuming my SQL script is used with SQLCMD and I use it to "source" other
scripts such as this:

BEGIN TRY
PRINT 'Installing Common'
BEGIN TRANSACTION T1
:r Create\Common.SQL -- Does multiple INSERT
PRINT 'Installing Add-on'
IF @@TranCount > 0
BEGIN
:r Create\AddOn.SQL -- Does multiple INSERT
COMMIT TRANSACTION T1
END
END TRY
BEGIN CATCH
ROLLBACK TRANSACTION T1
END CATCH
GO

Then my question is, would the approach you mentioned with @@transcount
work here as well? or does it get "broken" by the fact that two child
scripts (:r) are sourced?
Well, that depends on what it is those files. If there are any GO
in them, you will get a syntax error for the BEGIN TRY without
a matching END TRY. Unless there is one in the file you include.

But if there are no GO in the file, this should work fine.


--
Erland Sommarskog, SQL Server MVP, esquel (AT) sommarskog (DOT) se

Books Online for SQL Server 2005 at
http://www.microsoft.com/technet/pro...ads/books.mspx
Books Online for SQL Server 2000 at
http://www.microsoft.com/sql/prodinf...ons/books.mspx


Reply With Quote
  #37  
Old   
Erland Sommarskog
 
Posts: n/a

Default Re: About PRINT and other SQLCMD questions - 06-03-2008 , 04:59 PM



.....DotNet4Ever.... (hate.spam (AT) nowhere (DOT) com) writes:
Quote:
Just another question on this topic...

Assuming my SQL script is used with SQLCMD and I use it to "source" other
scripts such as this:

BEGIN TRY
PRINT 'Installing Common'
BEGIN TRANSACTION T1
:r Create\Common.SQL -- Does multiple INSERT
PRINT 'Installing Add-on'
IF @@TranCount > 0
BEGIN
:r Create\AddOn.SQL -- Does multiple INSERT
COMMIT TRANSACTION T1
END
END TRY
BEGIN CATCH
ROLLBACK TRANSACTION T1
END CATCH
GO

Then my question is, would the approach you mentioned with @@transcount
work here as well? or does it get "broken" by the fact that two child
scripts (:r) are sourced?
Well, that depends on what it is those files. If there are any GO
in them, you will get a syntax error for the BEGIN TRY without
a matching END TRY. Unless there is one in the file you include.

But if there are no GO in the file, this should work fine.


--
Erland Sommarskog, SQL Server MVP, esquel (AT) sommarskog (DOT) se

Books Online for SQL Server 2005 at
http://www.microsoft.com/technet/pro...ads/books.mspx
Books Online for SQL Server 2000 at
http://www.microsoft.com/sql/prodinf...ons/books.mspx


Reply With Quote
Reply




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.3
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.