Showing posts with label stored. Show all posts
Showing posts with label stored. Show all posts

Friday, March 30, 2012

Openquery with a sub-sql referening sqlserver table.

Hello.
I need to do a openquery to a linked server, and get record with id no in a sub select pointing to a table stored in SQLServer.
I have something like this:

select * into tmptable
from openquery (select * from linkedserverTable where id not in (select distinct(id) from sqlserverTable))

How to make sqserverTable not pointing to linked server, but sqlserver ?

Rgds

JCselect *
into tmptable
from openquery (linkedserver,'select * from linkedserverTable')
where id not in (select distinct id from sqlserverTable)

OPENQUERY vs. sp_executesql which is better?

I have recently seen the OPENQUERY function in a stored procedure which
was used to INSERT values into a table on a remote server. However, I
normally use the sp_executesql stored proc.
Can any one shed some light on which method is better and in what
cases?
The following code is from Microsoft website, not my own.
http://msdn.microsoft.com/library/d...br />
5xix.asp
<MS CODE>
EXEC sp_addlinkedserver 'OracleSvr',
'Oracle 7.3',
'MSDAORA',
'ORCLDB'
GO
SELECT *
FROM OPENQUERY(OracleSvr, 'SELECT name, id FROM joe.titles')
GO
</MS CODE>
VS.
<MYCODE>
sp_executesql N'SELECT name, id FROM OracleSvr.dbname.joe.titles'
-- OR
OracleSvr..sp_executesql N'SELECT name, id FROM dbname.joe.titles'
</MYCODE>
Thanks for your time folks.
Johnny DWhy would you even consider sp_executesql in your case? There is no need to
use dynamic sql to access a linked server.
Andrew J. Kelly SQL MVP
"Johnny D" <john.dacosta@.gmail.com> wrote in message
news:1148649898.280530.174390@.j73g2000cwa.googlegroups.com...
>I have recently seen the OPENQUERY function in a stored procedure which
> was used to INSERT values into a table on a remote server. However, I
> normally use the sp_executesql stored proc.
> Can any one shed some light on which method is better and in what
> cases?
> The following code is from Microsoft website, not my own.
> http://msdn.microsoft.com/library/d... />
z_5xix.asp
> <MS CODE>
> EXEC sp_addlinkedserver 'OracleSvr',
> 'Oracle 7.3',
> 'MSDAORA',
> 'ORCLDB'
> GO
>
> SELECT *
> FROM OPENQUERY(OracleSvr, 'SELECT name, id FROM joe.titles')
> GO
> </MS CODE>
> VS.
> <MYCODE>
> sp_executesql N'SELECT name, id FROM OracleSvr.dbname.joe.titles'
> -- OR
> OracleSvr..sp_executesql N'SELECT name, id FROM dbname.joe.titles'
> </MYCODE>
>
> Thanks for your time folks.
>
> Johnny D
>|||Sorry Andrew, this was an oversight in me writing a simple query to
illustrate my question...
The reason for this is I would use a cursor to loop through my
different servernames
DECLARE @.rc INT
DECLARE @.v_sql NVARCHAR(4000)
DECLARE @.vc_servername VARCHAR(100)
DECLARE c_myservers CURSOR
FOR SELECT
servername
FROM listservers
WHERE active=1
FOR READ ONLY
OPEN c_myservers
FETCH NEXT FROM c_myservers INTO @.vc_servername
WHILE (@.@.FETCHSTATUS = 0 )
BEGIN
SET @.v_sql = N'SELECT name, id FROM ['+@.vc_servername +
'].dbname.joe.titles'
EXEC @.rc = sp_executesql @.v_sql
-- if @.rc <> 0
-- etc...
FETCH NEXT FROM c_myservers INTO @.vc_servername
END
CLOSE c_myservers
DEALLOCATE c_myservers
sp_executesql N'SELECT name, id FROM OracleSvr.dbname.joe.titles'|||Well one key point of using OPENQUERY is that it passes the statement to the
other server where it is executed as is. That way the remote server can
choose the proper plan for that statement without regard to what the rest of
the statement is that was issued locally. Kind of hard to explain but it is
truly a pass-through query where as a linked server query may be influenced
by the rest of the statement. For instance a join to a local table.
Andrew J. Kelly SQL MVP
"Johnny D" <john.dacosta@.gmail.com> wrote in message
news:1148652836.663893.44660@.g10g2000cwb.googlegroups.com...
> Sorry Andrew, this was an oversight in me writing a simple query to
> illustrate my question...
> The reason for this is I would use a cursor to loop through my
> different servernames
> DECLARE @.rc INT
> DECLARE @.v_sql NVARCHAR(4000)
> DECLARE @.vc_servername VARCHAR(100)
> DECLARE c_myservers CURSOR
> FOR SELECT
> servername
> FROM listservers
> WHERE active=1
> FOR READ ONLY
> OPEN c_myservers
> FETCH NEXT FROM c_myservers INTO @.vc_servername
> WHILE (@.@.FETCHSTATUS = 0 )
> BEGIN
> SET @.v_sql = N'SELECT name, id FROM ['+@.vc_servername +
> '].dbname.joe.titles'
> EXEC @.rc = sp_executesql @.v_sql
> -- if @.rc <> 0
> -- etc...
> FETCH NEXT FROM c_myservers INTO @.vc_servername
> END
> CLOSE c_myservers
> DEALLOCATE c_myservers
>
> sp_executesql N'SELECT name, id FROM OracleSvr.dbname.joe.titles'
>|||Johnny D (john.dacosta@.gmail.com) writes:
> I have recently seen the OPENQUERY function in a stored procedure which
> was used to INSERT values into a table on a remote server. However, I
> normally use the sp_executesql stored proc.
> Can any one shed some light on which method is better and in what
> cases?
I think they are as comparable as apples and oranges.
Apparently you loop over servers. That is nothing OPENQUERY can help
you with - the server name must be a constant.
Rather your choice is between:
SELECT @.sql = 'SELECT ... FROM ' + @.server + 'catalog.schema.tbl'
and
SELECT @.sql = 'SELECT ... FROM OPENQUERY(' + @.server + ', ' +
'''SELECT ... FROM catalog.schema.tbl'')'
That is, accessing the table in four-partnotation, or running a
passthrough query.

><MYCODE>
> OracleSvr..sp_executesql N'SELECT name, id FROM dbname.joe.titles'
></MYCODE>
Ehum, I don't think you will find sp_executesql on Oracle...
Erland Sommarskog, SQL Server MVP, esquel@.sommarskog.se
Books Online for SQL Server 2005 at
http://www.microsoft.com/technet/pr...oads/books.mspx
Books Online for SQL Server 2000 at
http://www.microsoft.com/sql/prodin...ions/books.mspx

Openquery Help Requested

sql server = server A
sybase = server B (set up as a linked server in A)
I have a stored procedure in A that contains the following statement:
SELECT * FROM OPENQUERY(B, 'exec storedproc')
which runs the procedure in B just fine. It truncates a table in B and
then populates it with data from various queries. The issue is later in
the stored procedure issued from A I perform an insert where I grab the
data inserted into the table in B and insert that data into a table in
A. It seems as though everytime a number of records are inserted into
the table in A the statement above: SELECT * FROM OPENQUERY(B, 'exec
storedproc') is run again and again. Does anybody know why this is
occurring and how I can stop this from occurring?
Thanks,
E> the stored procedure issued from A I perform an insert where I grab the
> data inserted into the table in B and insert that data into a table in
> A. It seems as though everytime a number of records are inserted into
> the table in A the statement above: SELECT * FROM OPENQUERY(B, 'exec
> storedproc') is run again and again. Does anybody know why this is
> occurring and how I can stop this from occurring?
You mean that later within 'storedproc' you are perfoming insert into a
table that is resided on server 'A' and you have seen in SQL Server Profiler
that it runs SELECT * FROM OPENQUERY(B, 'exec> storedproc') many times. Am
I right?
"w" <ebrooks@.sbcglobal.net> wrote in message
news:1136953074.780909.282800@.g14g2000cwa.googlegroups.com...
> sql server = server A
> sybase = server B (set up as a linked server in A)
> I have a stored procedure in A that contains the following statement:
> SELECT * FROM OPENQUERY(B, 'exec storedproc')
> which runs the procedure in B just fine. It truncates a table in B and
> then populates it with data from various queries. The issue is later in
> the stored procedure issued from A I perform an insert where I grab the
> data inserted into the table in B and insert that data into a table in
> A. It seems as though everytime a number of records are inserted into
> the table in A the statement above: SELECT * FROM OPENQUERY(B, 'exec
> storedproc') is run again and again. Does anybody know why this is
> occurring and how I can stop this from occurring?
> Thanks,
> E
>|||Well the reason I know that it keeps reissuing that statement is that
while the table in A is being populated after a number of records have
been inserted the table in B is truncated and repopulated again and
this cycle goes on until the table in A has been completely populated.
E
Uri Dimant wrote:
> You mean that later within 'storedproc' you are perfoming insert into a
> table that is resided on server 'A' and you have seen in SQL Server Profil
er
> that it runs SELECT * FROM OPENQUERY(B, 'exec> storedproc') many times. A
m
> I right?
>
> "w" <ebrooks@.sbcglobal.net> wrote in message
> news:1136953074.780909.282800@.g14g2000cwa.googlegroups.com...|||Well the reason I know that it keeps reissuing that statement is that
while the table in A is being populated after a number of records have
been inserted the table in B is truncated and repopulated again and
this cycle goes on until the table in A has been completely populated.
E
Uri Dimant wrote:
> You mean that later within 'storedproc' you are perfoming insert into a
> table that is resided on server 'A' and you have seen in SQL Server Profil
er
> that it runs SELECT * FROM OPENQUERY(B, 'exec> storedproc') many times. A
m
> I right?
>
> "w" <ebrooks@.sbcglobal.net> wrote in message
> news:1136953074.780909.282800@.g14g2000cwa.googlegroups.com...

OPENQUERY and variable question

I am trying to create a stored proc that uses OPENQUERY to get data from a db2 database. Can anyone look at the code below and let me know what I am doing wrong.

This is my error msg:

Msg 156, Level 15, State 1, Line 1

Incorrect syntax near the keyword 'SELECT'.

Msg 170, Level 15, State 1, Line 2

Line 2: Incorrect syntax near ')'.

This is my code:

USE [FVDashBoard]

GO

SET ANSI_NULLS ON

GO

SET QUOTED_IDENTIFIER ON

GO

ALTER PROCEDURE [dbo].[spDaily_TBT_Load_OpenQuery]

as

-- define variables

declare @.FM_DT char(10)

set @.FM_DT = (SELECT CALENDAR_DT FROM dbo.PROD_SCHD WHERE(ISSUER_NO = 90)AND (CALENDAR_DT =CONVERT(VARCHAR(10), GETDATE() - 2, 120)))

declare @.remotesql nvarchar(4000)

set @.remotesql =

'select * from OPENQUERY (BACARDI, '+

'SELECT BRAND_NO FROM WRKCON.DLY_TBT_RCNCLTN_CONTROL

WHERE SOR_REC_CREAT_DT ='+@.FM_DT+ ')'

PRINT @.remotesql

EXEC (@.remotesql)

Thanks!

The second parameter of OPENQUERY (sql statement) should be string – enclosed by single quote. Try the below query..

Code Snippet

set @.remotesql =

'select * from OPENQUERY (BACARDI, '+

'''SELECT BRAND_NO FROM WRKCON.DLY_TBT_RCNCLTN_CONTROL

WHERE SOR_REC_CREAT_DT ='+@.FM_DT+ ''')'

|||

This statement

'select * from OPENQUERY (BACARDI, '+

'SELECT BRAND_NO FROM WRKCON.DLY_TBT_RCNCLTN_CONTROL

WHERE SOR_REC_CREAT_DT ='+@.FM_DT+ ')'

seems to be missing a closing parenthesis.

|||

Thanks so much for your reply.

As a follow-up question, how could I change the vaule of @.FM_DT? Currently the value of the variable is something like 2007-08-03. What I need is for the variable to be something like '2007-08-03'. Do you know of a way to do this.

Thanks for your help!

|||

You need to add a few more quotes...

Something like this:

= '''+ @.FM_DT + ''')'

Do a PRINT or SELECT on your statement until it is correct.

OPENQUERY and unicode from MySQL

Hi, all. Using SQL 2005. When I execute this query against a MySQL database set up as a linked server, cyrillic text stored in unicode in MySQL shows up as question marks (?).

SELECT *
FROM
OPENQUERY(
LINKEDSERVER,
'SELECT * FROM documents
)

Clearly, some kind of unicode issue. I've spent a few hours reading in BOL and searching online. Must be something simple, but I'm not finding a solution. If anyone has suggestions, I'd be very grateful.

Stephen

Just to follow up, my testing this morning suggests that this is an issue with the MySQL OBDC driver, used to create the connection to the linked server in SQL Server. So if anyone has solved this issue before, of course I'd be happy to hear the answer. Has anyone used a different driver to connect to MySQL as a linked server? I don't think I can use the Cherry City Software OLE DB provider, because it doesn't seem to support large text columns (http://cherrycitysoftware.com/CCS/Providers/ProvMySQL.aspx). I need a way to connect to MySQL as a linked server, using unicode (multilingual text in different rows) and text storage in some row columns at 50,000 bytes or more.

Thanks for any suggestions.

Stephen

Monday, March 26, 2012

Opening password protected Excel files

I have a stored procedure in which I am importing data from a password protected Excel file to a SQL table. The file comes from our client and the password cannot be removed before sending, per his company policy.

I would like to create a DTS package to open the file and import the data. Is there a way to pass the password to the DTS package?

Thanks!May refer to this KBA (http://support.microsoft.com/default.aspx?scid=kb;EN-US;Q211378).|||I can do this if I am using Excel, but I need to do it from a stored procedure. Is this possible using TSQL?

Thanks!|||Honestly I never tried, you may search under SQL DTS (http://www.sqldts.com) for further information.|||I got it!!! One of my coworkers (who was out when I needed the answer yesterday) had the solution!

dtsrun /Sservername /Uuid /Ppwd /Npackagename /AFileName:8= excelfilename /APassword:8=excelpwd

:-)|||Good keep it up, your reply help others.

Opening package stored in MSDB

I created a package using the Import\Export wizard and saved it to the local Sql server. Under Management Studio I can see the package, can run in, import it, export it BUT how am I supposed to edit (modify the thing) it?

TIA,

barkingdog

You can make simple edits like changing the property, enabling / disabling task etc by exporting the SSIS package as dtsx files in file system and opening it in SQL Server Management Studio.

To perform more advanced functionalities -like adding new tasks / flows - you need to open and edit the dtsx package in Visual Studio / SQL Server Business Intelligence Development Studio.

Thanks,
Loonysan

|||

Loonysan,

What you described strikes me as totally counter-intuitive. Under sql 2000 after I create and save a simple package, I can double-click it in Enteprse manager (the package opens), and proceed to work on it. End of story.

If I undestood what you said, I have to export my sql 2005 package (say, stored in sql servr) to a dtsx file and then import that into BIDS. This seems overly complicated to me.

Thanks,

Barkingdog.

|||

In SQL 2000 one edited and managed DTS packages in the same environment. This was perhaps ok when packages were simple utilites for the DBA. But in SQL 2005, SSIS Packages are much richer objects and have a full developer environment to support them, as well as a better management environment.

So in 2005 we have BIDS for developing (editing) and Management Studio for administration of deployed packages.

Just like a code project, one typically develops in a specialised environment and then deploys to the server. The developers code (package) is stored where the developer wants it - perhaps in version control. The deployed version lives on the server.

Modifying the version on the server is not good practice. One should modify the version kept in the development environment and deploy the new version to the server.

Some have discovered that it is possible to open a package in the management studio, but as pointed out, this is a most limited experience as it does not have the full range of development features. It may be useful for a quick fix to a property, but even then I would not recommend it.

Is this more complex than in 2000? Perhaps, but practices will should be better for it.

Donald

|||How do you find the SSIS package to save as a file once it is in MSDB? When I go to SSIS, the package itself doesn't show. I'm using Instances, and it will only open for the default install|||

Megan,

You need to go on to the server and edit the file C:\Program Files\Microsoft SQL Server\90\DTS\Binn\MsDtsSrvr.ini.xml

Change <ServerName>.</ServerName> to <ServerName>(your server)\(instance)</ServerName>

Then restart SSIS.

I agree with you that this is counter-intuitive. I am so disappointed with all of SQL Server 2005. Everything has become harder to use, and it's plagued with bugs and problems. I don't know what MS was thinking.

|||

AndyHzzzz wrote:

Megan,

You need to go on to the server and edit the file C:\Program Files\Microsoft SQL Server\90\DTS\Binn\MsDtsSrvr.ini.xml

Change <ServerName>.</ServerName> to <ServerName>(your server)\(instance)</ServerName>

Then restart SSIS.

I agree with you that this is counter-intuitive. I am so disappointed with all of SQL Server 2005. Everything has become harder to use, and it's plagued with bugs and problems. I don't know what MS was thinking.

Andy,
Did you read Donald's post? *That* is what Microsoft was thinking and I agree with it. SSIS is more of an enterprise development tool, not the toy that DTS was and hence it needs to follow a more rigid methodology.|||

Phil,

I did read Donald's post, and I understand what he is saying. However, that doesn't excuse the fact that I can create a package in the Import/Export wizard, configure it, run it, re-run it, re-configure it, etc., all from within that wizard, but if I ever close that wizard, I have to go to a completely different environment to work with that package again. That, to me, is bad interface design.

Furthermore, consider the actual steps in all of this. Today I needed to import 4 tables from Access to SQL Server. These were the steps involved (excluding cursing and searching Books Online):

Started Import/Export wizard

Attempted import of 4 Access tables using default options

Got errors regarding data conversion, clicked 'Back' to the mappings dialog, changed datatypes (Repeat)

Successfully imported the data.

Closed the Wizard.

Later, realized that I wanted to change some datatypes of the target fields.

Looked for my package in Management Studio. Got an error when selecting MSDB store

Modified MsDtsSrvr.ini.xml file on server. Re-started Integration Services (good thing I have admin privileges)

Found my package, exported to file, opened in Visual Studio.

Attempted to modify the SQL statement "Preparation SQL Task", where the target tables are created.

Got an error telling me that "CREATE TABLE" statements are not allowed, and cannot be parsed (the wizard created this package, remember. Also, this SQL statement was full of embedded carriage returns, so I could only edit the first CREATE TABLE statement anyway).

Copied the CREATE TABLE statements into a text file, modified the task to read the SQL from that file.

Changed the datatypes in the text file.

Ran the package. Success.

What did I gain from this new methodology? Nothing. I was not trying to develop an enterprise application, I just wanted to import 4 tables! This story is typical of my experiences with 2005. Simple tasks have become adventures through seemingly untested tools.

Furthermore, even if I did need to develop the sort of app that SSIS is geared toward, I don't trust it. I have run into too many weird problems with this whole release.

Andy

Opening package stored in MSDB

I created a package using the Import\Export wizard and saved it to the local Sql server. Under Management Studio I can see the package, can run in, import it, export it BUT how am I supposed to edit (modify the thing) it?

TIA,

barkingdog

You can make simple edits like changing the property, enabling / disabling task etc by exporting the SSIS package as dtsx files in file system and opening it in SQL Server Management Studio.

To perform more advanced functionalities -like adding new tasks / flows - you need to open and edit the dtsx package in Visual Studio / SQL Server Business Intelligence Development Studio.

Thanks,
Loonysan

|||

Loonysan,

What you described strikes me as totally counter-intuitive. Under sql 2000 after I create and save a simple package, I can double-click it in Enteprse manager (the package opens), and proceed to work on it. End of story.

If I undestood what you said, I have to export my sql 2005 package (say, stored in sql servr) to a dtsx file and then import that into BIDS. This seems overly complicated to me.

Thanks,

Barkingdog.

|||

In SQL 2000 one edited and managed DTS packages in the same environment. This was perhaps ok when packages were simple utilites for the DBA. But in SQL 2005, SSIS Packages are much richer objects and have a full developer environment to support them, as well as a better management environment.

So in 2005 we have BIDS for developing (editing) and Management Studio for administration of deployed packages.

Just like a code project, one typically develops in a specialised environment and then deploys to the server. The developers code (package) is stored where the developer wants it - perhaps in version control. The deployed version lives on the server.

Modifying the version on the server is not good practice. One should modify the version kept in the development environment and deploy the new version to the server.

Some have discovered that it is possible to open a package in the management studio, but as pointed out, this is a most limited experience as it does not have the full range of development features. It may be useful for a quick fix to a property, but even then I would not recommend it.

Is this more complex than in 2000? Perhaps, but practices will should be better for it.

Donald

|||How do you find the SSIS package to save as a file once it is in MSDB? When I go to SSIS, the package itself doesn't show. I'm using Instances, and it will only open for the default install|||

Megan,

You need to go on to the server and edit the file C:\Program Files\Microsoft SQL Server\90\DTS\Binn\MsDtsSrvr.ini.xml

Change <ServerName>.</ServerName> to <ServerName>(your server)\(instance)</ServerName>

Then restart SSIS.

I agree with you that this is counter-intuitive. I am so disappointed with all of SQL Server 2005. Everything has become harder to use, and it's plagued with bugs and problems. I don't know what MS was thinking.

|||

AndyHzzzz wrote:

Megan,

You need to go on to the server and edit the file C:\Program Files\Microsoft SQL Server\90\DTS\Binn\MsDtsSrvr.ini.xml

Change <ServerName>.</ServerName> to <ServerName>(your server)\(instance)</ServerName>

Then restart SSIS.

I agree with you that this is counter-intuitive. I am so disappointed with all of SQL Server 2005. Everything has become harder to use, and it's plagued with bugs and problems. I don't know what MS was thinking.

Andy,
Did you read Donald's post? *That* is what Microsoft was thinking and I agree with it. SSIS is more of an enterprise development tool, not the toy that DTS was and hence it needs to follow a more rigid methodology.|||

Phil,

I did read Donald's post, and I understand what he is saying. However, that doesn't excuse the fact that I can create a package in the Import/Export wizard, configure it, run it, re-run it, re-configure it, etc., all from within that wizard, but if I ever close that wizard, I have to go to a completely different environment to work with that package again. That, to me, is bad interface design.

Furthermore, consider the actual steps in all of this. Today I needed to import 4 tables from Access to SQL Server. These were the steps involved (excluding cursing and searching Books Online):

Started Import/Export wizard

Attempted import of 4 Access tables using default options

Got errors regarding data conversion, clicked 'Back' to the mappings dialog, changed datatypes (Repeat)

Successfully imported the data.

Closed the Wizard.

Later, realized that I wanted to change some datatypes of the target fields.

Looked for my package in Management Studio. Got an error when selecting MSDB store

Modified MsDtsSrvr.ini.xml file on server. Re-started Integration Services (good thing I have admin privileges)

Found my package, exported to file, opened in Visual Studio.

Attempted to modify the SQL statement "Preparation SQL Task", where the target tables are created.

Got an error telling me that "CREATE TABLE" statements are not allowed, and cannot be parsed (the wizard created this package, remember. Also, this SQL statement was full of embedded carriage returns, so I could only edit the first CREATE TABLE statement anyway).

Copied the CREATE TABLE statements into a text file, modified the task to read the SQL from that file.

Changed the datatypes in the text file.

Ran the package. Success.

What did I gain from this new methodology? Nothing. I was not trying to develop an enterprise application, I just wanted to import 4 tables! This story is typical of my experiences with 2005. Simple tasks have become adventures through seemingly untested tools.

Furthermore, even if I did need to develop the sort of app that SSIS is geared toward, I don't trust it. I have run into too many weird problems with this whole release.

Andy

sql

Opening package stored in MSDB

I created a package using the Import\Export wizard and saved it to the local Sql server. Under Management Studio I can see the package, can run in, import it, export it BUT how am I supposed to edit (modify the thing) it?

TIA,

barkingdog

You can make simple edits like changing the property, enabling / disabling task etc by exporting the SSIS package as dtsx files in file system and opening it in SQL Server Management Studio.

To perform more advanced functionalities -like adding new tasks / flows - you need to open and edit the dtsx package in Visual Studio / SQL Server Business Intelligence Development Studio.

Thanks,
Loonysan

|||

Loonysan,

What you described strikes me as totally counter-intuitive. Under sql 2000 after I create and save a simple package, I can double-click it in Enteprse manager (the package opens), and proceed to work on it. End of story.

If I undestood what you said, I have to export my sql 2005 package (say, stored in sql servr) to a dtsx file and then import that into BIDS. This seems overly complicated to me.

Thanks,

Barkingdog.

|||

In SQL 2000 one edited and managed DTS packages in the same environment. This was perhaps ok when packages were simple utilites for the DBA. But in SQL 2005, SSIS Packages are much richer objects and have a full developer environment to support them, as well as a better management environment.

So in 2005 we have BIDS for developing (editing) and Management Studio for administration of deployed packages.

Just like a code project, one typically develops in a specialised environment and then deploys to the server. The developers code (package) is stored where the developer wants it - perhaps in version control. The deployed version lives on the server.

Modifying the version on the server is not good practice. One should modify the version kept in the development environment and deploy the new version to the server.

Some have discovered that it is possible to open a package in the management studio, but as pointed out, this is a most limited experience as it does not have the full range of development features. It may be useful for a quick fix to a property, but even then I would not recommend it.

Is this more complex than in 2000? Perhaps, but practices will should be better for it.

Donald

|||How do you find the SSIS package to save as a file once it is in MSDB? When I go to SSIS, the package itself doesn't show. I'm using Instances, and it will only open for the default install|||

Megan,

You need to go on to the server and edit the file C:\Program Files\Microsoft SQL Server\90\DTS\Binn\MsDtsSrvr.ini.xml

Change <ServerName>.</ServerName> to <ServerName>(your server)\(instance)</ServerName>

Then restart SSIS.

I agree with you that this is counter-intuitive. I am so disappointed with all of SQL Server 2005. Everything has become harder to use, and it's plagued with bugs and problems. I don't know what MS was thinking.

|||

AndyHzzzz wrote:

Megan,

You need to go on to the server and edit the file C:\Program Files\Microsoft SQL Server\90\DTS\Binn\MsDtsSrvr.ini.xml

Change <ServerName>.</ServerName> to <ServerName>(your server)\(instance)</ServerName>

Then restart SSIS.

I agree with you that this is counter-intuitive. I am so disappointed with all of SQL Server 2005. Everything has become harder to use, and it's plagued with bugs and problems. I don't know what MS was thinking.

Andy,
Did you read Donald's post? *That* is what Microsoft was thinking and I agree with it. SSIS is more of an enterprise development tool, not the toy that DTS was and hence it needs to follow a more rigid methodology.|||

Phil,

I did read Donald's post, and I understand what he is saying. However, that doesn't excuse the fact that I can create a package in the Import/Export wizard, configure it, run it, re-run it, re-configure it, etc., all from within that wizard, but if I ever close that wizard, I have to go to a completely different environment to work with that package again. That, to me, is bad interface design.

Furthermore, consider the actual steps in all of this. Today I needed to import 4 tables from Access to SQL Server. These were the steps involved (excluding cursing and searching Books Online):

Started Import/Export wizard

Attempted import of 4 Access tables using default options

Got errors regarding data conversion, clicked 'Back' to the mappings dialog, changed datatypes (Repeat)

Successfully imported the data.

Closed the Wizard.

Later, realized that I wanted to change some datatypes of the target fields.

Looked for my package in Management Studio. Got an error when selecting MSDB store

Modified MsDtsSrvr.ini.xml file on server. Re-started Integration Services (good thing I have admin privileges)

Found my package, exported to file, opened in Visual Studio.

Attempted to modify the SQL statement "Preparation SQL Task", where the target tables are created.

Got an error telling me that "CREATE TABLE" statements are not allowed, and cannot be parsed (the wizard created this package, remember. Also, this SQL statement was full of embedded carriage returns, so I could only edit the first CREATE TABLE statement anyway).

Copied the CREATE TABLE statements into a text file, modified the task to read the SQL from that file.

Changed the datatypes in the text file.

Ran the package. Success.

What did I gain from this new methodology? Nothing. I was not trying to develop an enterprise application, I just wanted to import 4 tables! This story is typical of my experiences with 2005. Simple tasks have become adventures through seemingly untested tools.

Furthermore, even if I did need to develop the sort of app that SSIS is geared toward, I don't trust it. I have run into too many weird problems with this whole release.

Andy

Opening Mulitple Recordsets

I have a single .asp page that opens a connection and then sequentially
opens and closes 14 recordsets from stored procedures to obtain various
product information before closing the connection.

Is it common practice to do something like this? Or is opening 14
recordsets going to become a real problem when the page goes live and starts
getting high web traffic?

Thank you in advance for any information you might provide.

DaveHi

There is not really enough detail to know if you will have problems with
this although 14 seems quite a few it may not necessarily cause any problems
if the number of records being retrieved is not excessive. You should
simulate different levels of usage on your system before it goes live to get
some idea of the response.

If you are making muliple calls to different stored procedures, you may wish
to use a controlling procedure that returns multiple result sets see:
http://www.aspfaq.com/show.asp?id=2319

John

"Toonman" <toonman@.NOSPAMtoonman.com> wrote in message
news:4fZLb.10540$uF6.3301521@.news1.news.adelphia.n et...
> I have a single .asp page that opens a connection and then sequentially
> opens and closes 14 recordsets from stored procedures to obtain various
> product information before closing the connection.
> Is it common practice to do something like this? Or is opening 14
> recordsets going to become a real problem when the page goes live and
starts
> getting high web traffic?
> Thank you in advance for any information you might provide.
> Dave|||John,

Your information was extremely helpful... thank you again.

Dave

"John Bell" <jbellnewsposts@.hotmail.com> wrote in message
news:btpp2d$8ja$1@.sparta.btinternet.com...
> Hi
> There is not really enough detail to know if you will have problems with
> this although 14 seems quite a few it may not necessarily cause any
problems
> if the number of records being retrieved is not excessive. You should
> simulate different levels of usage on your system before it goes live to
get
> some idea of the response.
> If you are making muliple calls to different stored procedures, you may
wish
> to use a controlling procedure that returns multiple result sets see:
> http://www.aspfaq.com/show.asp?id=2319
> John
> "Toonman" <toonman@.NOSPAMtoonman.com> wrote in message
> news:4fZLb.10540$uF6.3301521@.news1.news.adelphia.n et...
> > I have a single .asp page that opens a connection and then sequentially
> > opens and closes 14 recordsets from stored procedures to obtain various
> > product information before closing the connection.
> > Is it common practice to do something like this? Or is opening 14
> > recordsets going to become a real problem when the page goes live and
> starts
> > getting high web traffic?
> > Thank you in advance for any information you might provide.
> > Dave

opening cursor on result set from stored proc

In SQL how can a cursor be opened to iterate the result set returned
from a stored proc

-Rahul Sood
rsood22@.yahoo.comYou can insert the procedure result set into a table. For example:

CREATE TABLE #ProcResults
(
SomeData int
)

INSERT INTO #ProcResults
EXEC MyProcedure

DECLARE MyCursor CURSOR
LOCAL FAST_FORWARD READ_ONLY FOR
SELECT * FROM #ProcResults

--
Hope this helps.

Dan Guzman
SQL Server MVP

--------
SQL FAQ links (courtesy Neil Pike):

http://www.ntfaq.com/Articles/Index...epartmentID=800
http://www.sqlserverfaq.com
http://www.mssqlserver.com/faq
--------

"Rahul Sood" <rsood22@.yahoo.com> wrote in message
news:aa3020f6.0308191503.68af9ec5@.posting.google.c om...
> In SQL how can a cursor be opened to iterate the result set returned
> from a stored proc
> -Rahul Sood
> rsood22@.yahoo.comsql

Opening a SP to modify gives incorrect name on TAB

In SQL Server Mangement Studio when I right click on stored procedure to modify the name on the tab does not have the name of the stored procedure on it.

Is there a way to turn this on? When I more than one open how do I tell where a certain sp is?

what u see in Management Studio is Schema.StoredProcedureName... u might be seeing in Summary window where u have Name first , then Schema and Then Created... Both are same ...

Madhu

|||

The tab name currently displays an autogenerated file name with server and database information (same as what a new query would do). It does not show the stored procedure name. Currently there is no way to turn this on. Please post a suggestion for this on http://connect.microsoft.com/sqlserver. Suggestions filed on this site go directly to our internal issue tracking system and are especially taken into consideration by the team while prioritizing the future work.

Thanks,
Kuntal

Opening a microsoft application from a stored procedure

Is there a way to call/launch a word document from a stored procedure?
Thanks for any help.Technically, yes. But why would you want to do such a crazy thing?
If you decided that you'd rather continue drinking the happy juice, you coul
d
use the sp_OA functions to call out to a COM dll that opens the Word documen
t
and does who knows what with it. If you were really ambitious, you could wri
te
an extended stored procedure in C++ to do the same thing.
Thomas
"Munch" <Munch@.discussions.microsoft.com> wrote in message
news:94F4A9C2-5399-4F64-B2D0-6C654A2DCCF7@.microsoft.com...
> Is there a way to call/launch a word document from a stored procedure?
> Thanks for any help.|||Would it be better to insert the path of the documents /files into a table
and have them executed from the tables? Is this possible? I know we used t
o
house jpgs in a table and referenced different jpgs depending on the user an
d
preferences. Can we do this with word docs and other MS Applications?
Thanks
"Thomas" wrote:

> Technically, yes. But why would you want to do such a crazy thing?
> If you decided that you'd rather continue drinking the happy juice, you co
uld
> use the sp_OA functions to call out to a COM dll that opens the Word docum
ent
> and does who knows what with it. If you were really ambitious, you could w
rite
> an extended stored procedure in C++ to do the same thing.
>
> Thomas
>
> "Munch" <Munch@.discussions.microsoft.com> wrote in message
> news:94F4A9C2-5399-4F64-B2D0-6C654A2DCCF7@.microsoft.com...
>
>|||Yes you can store any type of document in the database by using image column
s. A
column of type image can store any type of binary in its raw format. So, jus
t as
JPEGs can be stored in the db, so can Word documents. However, *storing* Wor
d
documents in the database is a far cry from *launching* Word from SQL Server
.
Determining whether you should store the actual files in the database instea
d of
a path is a cost-benefit analysis. Storing the files in the database makes
things like replication a bit easier and provides some security advantages.
In
addition, it makes accessing the file a little simpler in that everything is
retrieved from the database. The downside is that it makes it difficult to e
dit
the files as you need to make a program to pull and push the file to the
database. In addition, it bloats the size of the database making database
backups take longer.
Storing the path to the files makes it possible to view and edit the files
directly. However, you have to ensure that the path in the database stays in
sync with the path and filename on the disk. Where the path solution gets re
ally
tricky is with multiple servers and multiple sites. If that is not a concern
,
the I'd go with the path solution. I would ensure that websites cannot acces
s
the files directly, but rather go through a proxy that sends the binary to t
he
website code. In this way, you shield the storage mechanism and location fro
m
the website adding security. In addition, it allows you to easily switch
solutions without having to change the website code.
HTH
Thomas
"Munch" <Munch@.discussions.microsoft.com> wrote in message
news:28ACA9AE-D640-449C-9257-6690BA761FAA@.microsoft.com...
> Would it be better to insert the path of the documents /files into a table
> and have them executed from the tables? Is this possible? I know we used
to
> house jpgs in a table and referenced different jpgs depending on the user
and
> preferences. Can we do this with word docs and other MS Applications?
> Thanks
> "Thomas" wrote:
>|||Thomas:
Thanks for the valuable info. I will look into these options.
"Thomas Coleman" wrote:

> Yes you can store any type of document in the database by using image colu
mns. A
> column of type image can store any type of binary in its raw format. So, j
ust as
> JPEGs can be stored in the db, so can Word documents. However, *storing* W
ord
> documents in the database is a far cry from *launching* Word from SQL Serv
er.
> Determining whether you should store the actual files in the database inst
ead of
> a path is a cost-benefit analysis. Storing the files in the database makes
> things like replication a bit easier and provides some security advantages
. In
> addition, it makes accessing the file a little simpler in that everything
is
> retrieved from the database. The downside is that it makes it difficult to
edit
> the files as you need to make a program to pull and push the file to the
> database. In addition, it bloats the size of the database making database
> backups take longer.
> Storing the path to the files makes it possible to view and edit the files
> directly. However, you have to ensure that the path in the database stays
in
> sync with the path and filename on the disk. Where the path solution gets
really
> tricky is with multiple servers and multiple sites. If that is not a conce
rn,
> the I'd go with the path solution. I would ensure that websites cannot acc
ess
> the files directly, but rather go through a proxy that sends the binary to
the
> website code. In this way, you shield the storage mechanism and location f
rom
> the website adding security. In addition, it allows you to easily switch
> solutions without having to change the website code.
>
> HTH
>
> Thomas
>
> "Munch" <Munch@.discussions.microsoft.com> wrote in message
> news:28ACA9AE-D640-449C-9257-6690BA761FAA@.microsoft.com...
>
>

Friday, March 23, 2012

OpenDataSource with Microsoft.Jet.OLEDB.4 Excel from stored proced

I have a stored procedure which has the following line:
select * from FROM OpenDataSource( 'Microsoft.Jet.OLEDB.4.0',
'Data Source="\\MachineName\shared\account.xls";...Excel 8.0...
This stored procedure was called from a VB application. It's odd that
ONLY when ADO connection user need SA database role
AND \\MachineName\shared\account.xls was physical located in the same
machine of DATABASE
the stored procedure would work.
Otherwise it returned error like:
OLE DB error trace [OLE/DB Provider 'Microsoft.Jet.OLEDB.4.0'
IDBInitialize::Initialize returned 0x80004005: The provider did not give an
y
information about the error.]. 0 7300 -2147217900 Microsoft OLE DB Provider
for SQL Server 01000OLE DB provider 'Microsoft.Jet.OLEDB.4.0' reported an
error. The provider did not give any information about the error. 0 7399
-2147217900 Microsoft OLE DB Provider for SQL Server 42000
Database is SQL Server 2000 SP4. Registry DisallowAdhocAccess is 0.
Any suggestion?Because the security reson, I don't want ADO connection user has the SA role
,
and Excel file can located in any shared folder in the LAN.
"david" wrote:

> I have a stored procedure which has the following line:
> select * from FROM OpenDataSource( 'Microsoft.Jet.OLEDB.4.0',
> 'Data Source="\\MachineName\shared\account.xls";...Excel 8.0...
> This stored procedure was called from a VB application. It's odd that
> ONLY when ADO connection user need SA database role
> AND \\MachineName\shared\account.xls was physical located in the same
> machine of DATABASE
> the stored procedure would work.
> Otherwise it returned error like:
> OLE DB error trace [OLE/DB Provider 'Microsoft.Jet.OLEDB.4.0'
> IDBInitialize::Initialize returned 0x80004005: The provider did not give
any
> information about the error.]. 0 7300 -2147217900 Microsoft OLE DB Provide
r
> for SQL Server 01000OLE DB provider 'Microsoft.Jet.OLEDB.4.0' reported an
> error. The provider did not give any information about the error. 0 7399
> -2147217900 Microsoft OLE DB Provider for SQL Server 42000
> Database is SQL Server 2000 SP4. Registry DisallowAdhocAccess is 0.
> Any suggestion?
>sql

OpenDataSource with Microsoft.Jet.OLEDB.4 Excel from stored proced

I have a stored procedure which has the following line:
select * from FROM OpenDataSource( 'Microsoft.Jet.OLEDB.4.0',
'Data Source="\\MachineName\shared\account.xls";...Excel 8.0...
This stored procedure was called from a VB application. It's odd that
ONLY when ADO connection user need SA database role
AND \\MachineName\shared\account.xls was physical located in the same
machine of DATABASE
the stored procedure would work.
Otherwise it returned error like:
OLE DB error trace [OLE/DB Provider 'Microsoft.Jet.OLEDB.4.0'
IDBInitialize::Initialize returned 0x80004005: The provider did not give any
information about the error.]. 0 7300 -2147217900 Microsoft OLE DB Provider
for SQL Server 01000OLE DB provider 'Microsoft.Jet.OLEDB.4.0' reported an
error. The provider did not give any information about the error. 0 7399
-2147217900 Microsoft OLE DB Provider for SQL Server 42000
Database is SQL Server 2000 SP4. Registry DisallowAdhocAccess is 0.
Any suggestion?Because the security reson, I don't want ADO connection user has the SA role,
and Excel file can located in any shared folder in the LAN.
"david" wrote:
> I have a stored procedure which has the following line:
> select * from FROM OpenDataSource( 'Microsoft.Jet.OLEDB.4.0',
> 'Data Source="\\MachineName\shared\account.xls";...Excel 8.0...
> This stored procedure was called from a VB application. It's odd that
> ONLY when ADO connection user need SA database role
> AND \\MachineName\shared\account.xls was physical located in the same
> machine of DATABASE
> the stored procedure would work.
> Otherwise it returned error like:
> OLE DB error trace [OLE/DB Provider 'Microsoft.Jet.OLEDB.4.0'
> IDBInitialize::Initialize returned 0x80004005: The provider did not give any
> information about the error.]. 0 7300 -2147217900 Microsoft OLE DB Provider
> for SQL Server 01000OLE DB provider 'Microsoft.Jet.OLEDB.4.0' reported an
> error. The provider did not give any information about the error. 0 7399
> -2147217900 Microsoft OLE DB Provider for SQL Server 42000
> Database is SQL Server 2000 SP4. Registry DisallowAdhocAccess is 0.
> Any suggestion?
>

Wednesday, March 21, 2012

Open stored in Hexadecimal

How I can to open a encrypted stored procedure in Hexadecimal mode
with Query Analyzer?

ThanksYachi <yachi@.pointel.it> wrote in message news:<bpujh0himbt42fv9obbj477tnnqeu9162b@.4ax.com>...
> How I can to open a encrypted stored procedure in Hexadecimal mode
> with Query Analyzer?
> Thanks

In general, you won't get an answer to questions like this in a
newsgroup, because it's not always clear what the motive behind the
question is. However, if you really need to know, then Google should
be able to help...

Simon

Monday, March 12, 2012

Open File From Report?

Hello,

I am trying to open a file on a network drive from a report. The file's location that I need to open is stored in the db for each record. I have tried using javascript to open a new window using theFile:/// prefix. I have been able to open a new windows and navigate to a URL in this fashion by using a javascript window.open call and placing it in the navigation tab of the textbox. When I try this with a file, however, I get an access denied message. I was thinking to try opening the file by using the System.Diagnostic.Process.Start() method from code, but I'm not sure how to wire that up to the OnClick event of the textbox on the report. Does anyone have any ideas?

HI, ski081:

You can have a try to use the UNC path in the Navigate to the URL in the new windows:

If i misunderstand you about your question, please feel free to correct me and i will try to help you with more information.

I hope the above information will be helpful. If you have any issues or concerns, please let me know. It's my pleasure to be of assistance

|||

HI, ski081:

We are marking this issue as "Answered". If you have any new findings or concerns, please feel free to unmark the issue.
Thank you for your understanding!

Open file from report?

Hello,

I am trying to open a file on a network drive from a report. The file's location that I need to open is stored in the db for each record. I have tried using javascript to open a new window using the File:/// prefix. I have been able to open a new windows and navigate to a URL in this fashion by using a javascript window.open call and placing it in the navigation tab of the textbox. When I try this with a file, however, I get an access denied message. I was thinking to try opening the file by using the System.Diagnostic.Process.Start() method from code, but I'm not sure how to wire that up to the OnClick event of the textbox on the report. Does anyone have any ideas?

Could you point to a web page and then use a query string parameter to redirect to the file?

cheers,

Andrew

|||Hi, Andrew. Thanks for the reply. I solved this one yesterday. It was really simple, and I can't believe I didn't try it before. I was trying to open the .doc file in a new window using javascript (window.open) with the file:\\\ handle. I finally tried just putting the UNC path into the Navigate to URL field under the textbox's properties/navigation tab. This worked perfectly. It immediately opened Word and then loaded the file. For reference, this also works with a drive letter, such as C:\test.doc.

Open encryption key in stored procedure

Hi,
I would like to create a stored procedure, which accept RunAsUser, MasterKeyPassword and also ASymmetricKeyPassword. In this stored procedure, it call OPEN MASTER KEY and etc. I put these code in stored procedure so that my support staff can call it when doing maintenance by passing the parameter. I don't expect them to remember OPEN MASTER KEY and etc syntax.

However, I hit error "Invalid Syntax" when I run my code as below. Any ideas?

Thank you

-- ================================================
-- Template generated from Template Explorer using:
-- Create Procedure (New Menu).SQL
--
-- Use the Specify Values for Template Parameters
-- command (Ctrl-Shift-M) to fill in the parameter
-- values below.
--
-- This block of comments will not be included in
-- the definition of the procedure.
-- ================================================
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
-- =============================================
-- Author: <Author,,Name>
-- Create date: <Create Date,,>
-- Description: <Description,,>
-- =============================================
CREATE PROCEDURE GrantMe
-- Add the parameters for the stored procedure here
@.RunAsUser varchar(20), @.MasterKey varchar(30), @.ASKey varchar(30)
AS
BEGIN
-- SET NOCOUNT ON added to prevent extra result sets from
-- interfering with SELECT statements.
SET NOCOUNT ON;

EXEC AS USER=@.RunAsUser;

OPEN MASTER KEY DECRYPTION BY PASSWORD=@.MasterKey;

OPEN SYMMETRIC KEY HRMS
DECRYPTION BY ASYMMETRIC KEY FlexHRMS WITH PASSWORD=@.AsKey ;
END
GO

I don't believe DDL supports parameterization. You could use dynamic SQL, but it should be easier to simply use the DecryptByKeyAutoAsymKey built-in which will automatically open the symmetric key for you so you don't have to use the OPEN command.

Sung

|||

BTW, you should not have to call OPEN MASTER KEY if the ASYMMETRIC KEY is encrypted by password.

Sung

|||

DDL statements don’t support variables as arguments, therefore you need to change the OPEN MASTER KEY and OPEN SYMMETRIC KEY statements. Unfortunately , you will need to use dynamic SQL (the non-parameterized form) in order to execute such statements with user-defined content. Because you will need to create non-parameterized dynamic SQL, I really recommend reading about SQL injection and how to prevent it; below I included a few links regarding SQL Injection:

· Dynamic SQL & SQL Injection http://blogs.msdn.com/raulga/archive/2007/01/04/dynamic-sql-sql-injection.aspx

· SQL Injection http://msdn2.microsoft.com/en-us/library/ms161953.aspx

· New SQL Truncation Attacks And How To Avoid Them http://msdn.microsoft.com/msdnmag/issues/06/11/SQLSecurity/default.aspx

· Stop SQL Injection Attacks Before They Stop You http://msdn.microsoft.com/msdnmag/issues/04/09/sqlinjection/default.aspx

· Second-order Code Injection Attacks (http://www.ngssoftware.com/papers/SecondOrderCodeInjection.pdf)

I have some additional comments that hopefully will also help.

I am assuming that the intention of this SP is to open the DB master key (meaning it is not protected by the service master key) and open the symmetric key HRMS, leaving both keys opened in order to allow both of them to be used later in the same session, correct?

I would recommend adding comments specifying the intention of opening the keys and not closing them is intentional.

I am also assuming that the impersonation (EXECUTE AS USER) takes place because the calling context doesn’t have direct permission over either the symmetric key or the asymmetric key protecting it. Because the caller would need IMPERSONATE USER permission on @.RunAsUser, and this permission allows the calling user to impersonate that principal anytime, you may want to consider using EXECUTE AS in the module definition, or use digital signatures for allowing access to the keys instead.

I hope this information will be useful.

-Raul Garcia

SDE/T

SQL Server Engine

|||Hi,
Thank you for you comments.

>>digital signatures for allowing access to the keys instead.

Any reference for this?

Thank you

|||

Yes, see the following link:

http://msdn2.microsoft.com/en-us/library/ms181700.aspx

For examples, I have a few on my blog:

http://blogs.msdn.com/lcris/archive/2005/06/15/429631.aspx
http://blogs.msdn.com/lcris/archive/2006/01/13/512829.aspx

Thanks
Laurentiu

Open Encrypted Stored Procedure

Hi, i has another problem i think you can help me on,
I need to open a encrypted stored procedure, how can i do it??
Thanks.Ohhhh.. Microsoft and his security realy sucks...
here you have how.

Create Procedure Decryptsp2K (@.objName varchar(50))
AS
-- INPUT: object name (stored procedure, view or trigger)
DECLARE @.a nvarchar(4000), @.b nvarchar(4000), @.c nvarchar(4000), @.d nvarchar(4000), @.i int, @.t bigint
--get encrypted data
SET @.a=(SELECT ctext FROM syscomments WHERE id = object_id(@.objName))
SET @.b='ALTER PROCEDURE '+ @.objName +' WITH ENCRYPTION AS '+REPLICATE('-', 4000-62)
EXECUTE (@.b)
--get encrypted bogus SP
SET @.c=(SELECT ctext FROM syscomments WHERE id = object_id(@.objName))
SET @.b='CREATE PROCEDURE '+ @.objName +' WITH ENCRYPTION AS '+REPLICATE('-', 4000-62)
--start counter
SET @.i=1
--fill temporary variable
SET @.d = replicate(N'A', (datalength(@.a) / 2))
--loop
WHILE @.i<=datalength(@.a)/2
BEGIN
--xor original+bogus+bogus encrypted
SET @.d = stuff(@.d, @.i, 1,
NCHAR(UNICODE(substring(@.a, @.i, 1)) ^
(UNICODE(substring(@.b, @.i, 1)) ^
UNICODE(substring(@.c, @.i, 1)))))
SET @.i=@.i+1
END
--drop original SP
EXECUTE ('drop PROCEDURE '+ @.objName)
--remove encryption
--try to preserve case
SET @.d=REPLACE((@.d),'WITH ENCRYPTION', '')
SET @.d=REPLACE((@.d),'With Encryption', '')
SET @.d=REPLACE((@.d),'with encryption', '')
IF CHARINDEX('WITH ENCRYPTION',UPPER(@.d) )>0
SET @.d=REPLACE(UPPER(@.d),'WITH ENCRYPTION', '')
--replace SP
execute( @.d)

GO|||Thank you for you code, is exactly what i need and works perfect!