SQL 2012 THROW in SP That needs to be run on SQL 2005 and 2012

Let me start of by saying that I know SQL 2005 doesn't support the THROW feature.

I need a SP to be run on SQL Server 2012 and 2005. I would like to use the following section of code to allow SQL server generate a different error depending on the version of SQL server. But I am getting an error when trying to create the SP on the SQL 2005 server. Is there any way to get around this error when installing the SP?

Code:

IF LEFT(@@VERSION, 25) LIKE ('%2012') BEGIN     ;THROW 50013, @FullErrorMessage, 1 END ELSE IF LEFT(@@VERSION, 25) LIKE ('%2005') BEGIN     RAISERROR(@FullErrorMessage, 11, 1) END 

Error:

Msg 102, Level 15, State 1, Procedure SPNAME, Line xxxx Incorrect syntax near 'THROW'.

Replay

Please use a dynamic statement:

IF LEFT(@@VERSION, 25) LIKE ('%2012') BEGIN EXEC sp_executesql N';THROW 50013, @FullMessage , 1','@FullMessage nvarchar(1000)',@[email protected] END ELSE IF LEFT(@@VERSION, 25) LIKE ('%2005') BEGIN RAISERROR(@FullErrorMessage, 11, 1) END

Category: sql server Time: 2016-07-29 Views: 3

Related post

iOS development

Android development

Python development

JAVA development

Development language

PHP development

Ruby development

search

Front-end development

Database

development tools

Open Platform

Javascript development

.NET development

cloud computing

server

Copyright (C) avrocks.com, All Rights Reserved.

processed in 0.215 (s). 12 q(s)