Showing posts with label alternative. Show all posts
Showing posts with label alternative. Show all posts

Wednesday, March 7, 2012

An alternative for Dynamic SQL required

Hey guys I've something like this which is a reauirement. I dont want to use
a dynamic SQL
eg is
create proc proc1
@.ownername varchar(100),
@.IPaddress varchar(15)
as
select a,b,c from Table1 t1
join Table2 t2 on t1.col1=t2.col2
where ((t1.OwnerFirstName LIKE '%'+ISNULL(@.ownername,A.OwnerFirstName)
+'%') OR
(t1.OwnerLastName LIKE '%'+ ISNULL(@.ownername,A.OwnerLastName) +'%'))
AND ((t1.ExternalIP LIKE '%'+ISNULL(@.IPaddress,DB.ExternalIP)+'%') OR
(t1.InternalIP LIKE '%'+ISNULL(@.IPaddress,DB.InternalIP)+'%'))
go
Hopefully you can see the situation here.
I have an app where I can select (either or fname or lname) and I can also
select (either or internal IP or external IP). The above proc will work for
either in both cases.
What I want to do in the stored proc is somehow check these conditions. I
dont want to use dynamic SQL. Can you suggest an alternative which will help
in performance when compard to Dynamic SQL? Thank you.One obvious performance issue is that you are performing a LIKE comparison
on a value that is left truncated. For example, if OwnerName is indexed,
then this is will result in an index scan:
where OwnerName LIKE 'John%'
However, the following would result in a non-indexed table scan:
where OwnerLastName LIKE '%Smith'
where OwnerLastName LIKE '%Smith%'
Also, read this document; specifically the paragraphs about "sargable"
comparison arguments.
http://www.microsoft.com/technet/pr...s/inside14.mspx
Actually, dynamic SQL may be the solution to your problem. If you could
construct your SQL on the application side or construct the SQL within the
procedure in a variable and execute using the T-SQL Exec function.
http://msdn.microsoft.com/library/d...br />
05ro.asp
You can use the Show Execution Plan feature of Query Analyzer to determine
if your query is properly utilizing an index.
http://msdn.microsoft.com/library/d... />
1_5pde.asp
"Tejas Parikh" <TejasParikh@.discussions.microsoft.com> wrote in message
news:8FD1CC5B-A8F9-4080-A75C-65D85E331CF9@.microsoft.com...
> Hey guys I've something like this which is a reauirement. I dont want to
> use
> a dynamic SQL
> eg is
> create proc proc1
> @.ownername varchar(100),
> @.IPaddress varchar(15)
> as
> select a,b,c from Table1 t1
> join Table2 t2 on t1.col1=t2.col2
> where ((t1.OwnerFirstName LIKE '%'+ISNULL(@.ownername,A.OwnerFirstName)
> +'%') OR
> (t1.OwnerLastName LIKE '%'+ ISNULL(@.ownername,A.OwnerLastName) +'%'))
> AND ((t1.ExternalIP LIKE '%'+ISNULL(@.IPaddress,DB.ExternalIP)+'%') OR
> (t1.InternalIP LIKE '%'+ISNULL(@.IPaddress,DB.InternalIP)+'%'))
> go
>
> Hopefully you can see the situation here.
> I have an app where I can select (either or fname or lname) and I can also
> select (either or internal IP or external IP). The above proc will work
> for
> either in both cases.
> What I want to do in the stored proc is somehow check these conditions. I
> dont want to use dynamic SQL. Can you suggest an alternative which will
> help
> in performance when compard to Dynamic SQL? Thank you.|||On Fri, 17 Mar 2006 09:05:26 -0800, Tejas Parikh wrote:

>Hey guys I've something like this which is a reauirement. I dont want to us
e
>a dynamic SQL
>eg is
>create proc proc1
>@.ownername varchar(100),
>@.IPaddress varchar(15)
>as
>select a,b,c from Table1 t1
> join Table2 t2 on t1.col1=t2.col2
>where ((t1.OwnerFirstName LIKE '%'+ISNULL(@.ownername,A.OwnerFirstName)
>+'%') OR
> (t1.OwnerLastName LIKE '%'+ ISNULL(@.ownername,A.OwnerLastName) +'%'))
> AND ((t1.ExternalIP LIKE '%'+ISNULL(@.IPaddress,DB.ExternalIP)+'%') OR
> (t1.InternalIP LIKE '%'+ISNULL(@.IPaddress,DB.InternalIP)+'%'))
>go
>
>Hopefully you can see the situation here.
>I have an app where I can select (either or fname or lname) and I can also
>select (either or internal IP or external IP). The above proc will work for
>either in both cases.
>What I want to do in the stored proc is somehow check these conditions. I
>dont want to use dynamic SQL. Can you suggest an alternative which will hel
p
>in performance when compard to Dynamic SQL? Thank you.
Hi Tejas,
Lots of useful information for this type of problem can be found on
Erland's page: http://www.sommarskog.se/dyn-search.html.
Hugo Kornelis, SQL Server MVP|||Tejas Parikh (TejasParikh@.discussions.microsoft.com) writes:
> Hey guys I've something like this which is a reauirement. I dont want to
> use a dynamic SQL
> eg is
> create proc proc1
> @.ownername varchar(100),
> @.IPaddress varchar(15)
> as
> select a,b,c from Table1 t1
> join Table2 t2 on t1.col1=t2.col2
> where ((t1.OwnerFirstName LIKE '%' + ISNULL(@.ownername,
> A.OwnerFirstName) +'%') OR
> (t1.OwnerLastName LIKE '%' + ISNULL(@.ownername,
> A.OwnerLastName) +'%'))
> AND ((t1.ExternalIP LIKE '%' + ISNULL(@.IPaddress,
> DB.ExternalIP) + '%') OR
> (t1.InternalIP LIKE '%' + ISNULL(@.IPaddress,
> DB.InternalIP)+'%'))
> go
Well, as long as you have the % first in the LIKE operations, this is
going to table scan no matter what you do, so there would not be much
point with using dynamic SQL for better performance. Your current code
would work fine.
I would recommend that you leave it to the users to specify any initial %
if they need it. Then there is a at least a ghost of a chance for
indexes to be used. It's difficult to give detailed suggestions though,
as I don't know the tables, and I suspect that your real procedures have
more than these two parameters.
But my article, that Hugo also pointed you to, might give you some
ideas: http://www.sommarskog.se/dyn-search.html.
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

Sunday, February 12, 2012

alternative way

SELECT *
FROM organization
WHERE (departmentID = divisionID) AND (divisionID = branchID) AND
(branchID = sectionID) AND (sectionID = unitID)

Is there anyway I can make this query more simlified w/o repeating the
same column in the where clause?

thanks
s/RC> SELECT *
> FROM organization
> WHERE (departmentID = divisionID) AND (divisionID = branchID) AND
> (branchID = sectionID) AND (sectionID = unitID)
> Is there anyway I can make this query more simlified w/o repeating the
> same column in the where clause?

SELECT *
FROM organization
WHERE departmentID = all (
select divisionID union
select branchID union
select sectionID union
select unitID
)

Craig|||"Craig Kelly" <cnkelly.nospam@.nospam.net> wrote in message
news:zsldc.35902$vo5.1148556@.bgtnsc05-news.ops.worldnet.att.net...
> > SELECT *
> > FROM organization
> > WHERE (departmentID = divisionID) AND (divisionID = branchID) AND
> > (branchID = sectionID) AND (sectionID = unitID)
> > Is there anyway I can make this query more simlified w/o repeating the
> > same column in the where clause?
> SELECT *
> FROM organization
> WHERE departmentID = all (
> select divisionID union
> select branchID union
> select sectionID union
> select unitID
> )

Keep in mind there's a very good chance the optimizer may rewrite the query
in any case.

> Craig|||I wonder it executes faster than the original query stmt?
thanks again,
s/RC

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!

Alternative to xp_sendmail on 64 Bit SQL Server 2000

I'm looking for any alternative methods that can be used in place of the
xp_sendmail extended stored procedure when running on a 64 bit machine with
the 64 bit version of SQL Server 2000.
Any proven suggestions would be extremely helpful.
Not sure if this can help:
http://www.sqldev.net/xp/xpsmtp.htm
Tom
Thomas A. Moreau, BSc, PhD, MCSE, MCDBA
SQL Server MVP
Columnist, SQL Server Professional
Toronto, ON Canada
www.pinpub.com
"Gordon Radley" <GordonRadley@.discussions.microsoft.com> wrote in message
news:DF298AAC-3340-47E4-BFA4-5006512B070D@.microsoft.com...
> I'm looking for any alternative methods that can be used in place of the
> xp_sendmail extended stored procedure when running on a 64 bit machine
> with
> the 64 bit version of SQL Server 2000.
> Any proven suggestions would be extremely helpful.
|||xp_smtp_sendmail doesn't work (probably because it's compiled for win32).
If anybody find a solution please tell me too.
"Gordon Radley" <GordonRadley@.discussions.microsoft.com> wrote in message
news:DF298AAC-3340-47E4-BFA4-5006512B070D@.microsoft.com...
> I'm looking for any alternative methods that can be used in place of the
> xp_sendmail extended stored procedure when running on a 64 bit machine
> with
> the 64 bit version of SQL Server 2000.
> Any proven suggestions would be extremely helpful.

Alternative to using USE in a PROCEDURE

is there a way to get around not using USE in a PROCEDURE?

I need to because I have a main site that inserts information into other DB's that i use for various subdomains. But without being able to use USE i cant select which database is needed.

thx in advanceshould i use the master database and prefix my procedures with sp_?|||Huh second time in 2 mins. Use the fully qualified path to the entity

<database>.<owner>.<entity>

alternative to union

hi, i have tables like sells, byus, rents, credits
they all have a FK to table partners - partner_guid
how do i get all sells, buys ... for a given partner w/ 1 query?
i`ve been thinking about UNION but it will require(will it ?) me to
write all where and join clauses 4 times
TIAyou can try a similar one as shown below
select * from
(
select col1,col2.. from table 1
union all
select col1,col2.. from table2
union all
select col1,col2.. from table3
)
x
inner join partners p on
x.partnerid = p.partnerid
where
p.PartnerName = 'xxx'
- Sha Anand
"Freddie" wrote:

> hi, i have tables like sells, byus, rents, credits
> they all have a FK to table partners - partner_guid
> how do i get all sells, buys ... for a given partner w/ 1 query?
> i`ve been thinking about UNION but it will require(will it ?) me to
> write all where and join clauses 4 times
> TIA
>|||Greetings,
"Freddie" <sure@.spam.com> wrote in message
news:uQhe9o2mGHA.1208@.TK2MSFTNGP03.phx.gbl...
> hi, i have tables like sells, byus, rents, credits
> they all have a FK to table partners - partner_guid
> how do i get all sells, buys ... for a given partner w/ 1 query?
> i`ve been thinking about UNION but it will require(will it ?) me to write
> all where and join clauses 4 times
Assuming a simple schema and that you want totals, here's one without UNION.
select
p.partner_guid,
sum(isnull(s.sale,0)) as total_sales,
sum(isnull(b.buy,0)) as total_purchases,
sum(isnull(r.rent,0)) as total_rents,
sum(isnull(c.credit,0)) as total_credits
from partners p
left outer join sells s
on s.partner_guid = p.partner_guid
left outer join buys b
on b.partner_guid = p.partner_guid
left outer join rents r
on r.partner_guid = p.partner_guid
left outer join credits c
on c.partner_guid = p.partner_guid
group by
p.partner_guid
Just add a WHERE clause to get the row for your input partner.
Regards,
Neale NOON|||>> hi, I have tables like sells, buys, rents, credits they all have a FK to
table partners - partner_guid <<
Please post DDL, so that people do not have to guess what the keys,
constraints, Declarative Referential Integrity, data types, etc. in
your schema are. Sample data is also a good idea, along with clear
specifications. It is very hard to debug code when you do not let us
see it.

>From your personal narrative, however, it sounds like you have
serioius attribute splitting problems. You have taken the values of an
attribute and made them into tables. Would you also split Personnel
into Male and Female?
And why did you think that a GUID is a key? How do you verify it?
Validate it? But, boy, it was quick and easy to code so you did not
have to think of RDBMS design, wasn't it?
You clearly have no idea what you are doing and really need to get more
help than you will find on a Newsgroup.

Alternative to T-SQL OpenXML

Hi,

Our application makes extensive use of XML to move data between ASP.NET and the backend SQL Server 2000 database. Lately we have found that the OpenXML statement is becoming a major performance bottleneck.

Could someone suggest a more efficient way of 1) passing data between the web and data tier or 2) alternatives to OpenXml/sp_prepare_document.

Regards
Arjun

Dear Arjun

First, how does your OpenXML code look like? There are some best practises that can have a large performance impact.

Secondly, are you using Service pack 4? That also has some sometimes substatial performance improvements.

Otherwise, I would recommend at looking at the SQLXML 3.0 XML Bulkload object, or a ADO.Net DataSet based approach.

Best regards

Michael

|||

Dear Michael,

Here's a code snippet. This is contained in a stored procedure which accepts the XML data as input. Any suggestions to tune this.

exec sp_xml_preparedocument @.outputDoc OUTPUT, @.strAddXML

Insert into @.Table(txtCategory,intFinYearEnd,fltTotalRevenue,fltCost,fltCostPer,fltCommPer,fltAprRev,fltMayRev , fltJunRev, fltJulRev,fltAugRev ,fltSepRev ,fltOctRev ,
fltNovRev ,fltDecRev ,fltJanRev ,fltFebRev ,fltMarRev )
Select txtCategory,intFinYearEnd,fltTotalRevenue,fltCost,fltCostPer,fltCommPer,fltAprRev,fltMayRev , fltJunRev, fltJulRev,fltAugRev ,fltSepRev ,fltOctRev ,
fltNovRev ,fltDecRev ,fltJanRev ,fltFebRev ,fltMarRev FROM OPENXML(@.outputDoc, 'DocXML/intRow',1)
with
(
txtCategory varchar(50),
intFinYearEnd int,
fltTotalRevenue float,
fltCost float,
fltCostPer float,
fltCommPer float,
fltAprRev float,
fltMayRev float,
fltJunRev float,
fltJulRev float,
fltAugRev float,
fltSepRev float,
fltOctRev float,
fltNovRev float,
fltDecRev float,
fltJanRev float,
fltFebRev float,
fltMarRev float
)

Regards
Arjun

|||

Hi Arjun

Sorry for the late reply but I was travelling.

The OpenXML statement that you show looks ok to me. Have you done some performance testing to see where the time is being spent? During parsing of the sp_xml_preparedocument or the actual OpenXML call?

How large is the XML that you are passing in? Note that SQL Server 2000 versions prior to SP4 used a parser that had some non-linear scaling problems during parsing of larger documents (which has been fixed with SP4). What service pack version are you using?

Best regards

Michael

Alternative to T-SQL OpenXML

Hi,

Our application makes extensive use of XML to move data between ASP.NET and the backend SQL Server 2000 database. Lately we have found that the OpenXML statement is becoming a major performance bottleneck.

Could someone suggest a more efficient way of 1) passing data between the web and data tier or 2) alternatives to OpenXml/sp_prepare_document.

Regards
Arjun

Dear Arjun

First, how does your OpenXML code look like? There are some best practises that can have a large performance impact.

Secondly, are you using Service pack 4? That also has some sometimes substatial performance improvements.

Otherwise, I would recommend at looking at the SQLXML 3.0 XML Bulkload object, or a ADO.Net DataSet based approach.

Best regards

Michael

|||

Dear Michael,

Here's a code snippet. This is contained in a stored procedure which accepts the XML data as input. Any suggestions to tune this.

exec sp_xml_preparedocument @.outputDoc OUTPUT, @.strAddXML

Insert into @.Table(txtCategory,intFinYearEnd,fltTotalRevenue,fltCost,fltCostPer,fltCommPer,fltAprRev,fltMayRev , fltJunRev, fltJulRev,fltAugRev ,fltSepRev ,fltOctRev ,
fltNovRev ,fltDecRev ,fltJanRev ,fltFebRev ,fltMarRev )
Select txtCategory,intFinYearEnd,fltTotalRevenue,fltCost,fltCostPer,fltCommPer,fltAprRev,fltMayRev , fltJunRev, fltJulRev,fltAugRev ,fltSepRev ,fltOctRev ,
fltNovRev ,fltDecRev ,fltJanRev ,fltFebRev ,fltMarRev FROM OPENXML(@.outputDoc, 'DocXML/intRow',1)
with
(
txtCategory varchar(50),
intFinYearEnd int,
fltTotalRevenue float,
fltCost float,
fltCostPer float,
fltCommPer float,
fltAprRev float,
fltMayRev float,
fltJunRev float,
fltJulRev float,
fltAugRev float,
fltSepRev float,
fltOctRev float,
fltNovRev float,
fltDecRev float,
fltJanRev float,
fltFebRev float,
fltMarRev float
)

Regards
Arjun

|||

Hi Arjun

Sorry for the late reply but I was travelling.

The OpenXML statement that you show looks ok to me. Have you done some performance testing to see where the time is being spent? During parsing of the sp_xml_preparedocument or the actual OpenXML call?

How large is the XML that you are passing in? Note that SQL Server 2000 versions prior to SP4 used a parser that had some non-linear scaling problems during parsing of larger documents (which has been fixed with SP4). What service pack version are you using?

Best regards

Michael

Alternative to Transactional Replication

I have a customer who has about 80 SQL 2005 servers in remote offices
with various WAN links. The distribution of the SQL servers are as
follows:
- 15 site servers (publishers) must update to a single regional server
(central subscriber), there are about 5 regional servers, each with
their own set of publishers, for a total of about 75 publishers and 5
subscribers.
- There is a single SQL server in central HQ which must get updates
from all of the regional servers, for a complete picture of all the
data from the site servers.
- The amount of updates at each site are minimal and only occur once
or twice per day. However, when the update does occur, it should be
pushed out with minimal delay to the regional server as well as the
central HQ server.
- The data at the regional and HQ locations must be available at all
times for reporting purposes. No updates will be performed at the
regional or HQ locations.
- SQL Transactional Replication in a central subscriber model has been
investigated as a possible solution, but has been eliminated as a
possibility at this time for various reasons.
What am considering is a solution similar to the following.
Create a Trigger (http://msdn2.microsoft.com/en-us/library/
ms189799.aspx) that automatically updates a linked server upon update
of a table or view at the site server. Each site office would have a
linked server back to the SQL server in the regional office as well as
the SQL server in the central HQ office. This would ensure that each
time the data is updated, it is automatically updated on the remote
servers as well.
Any thoughts on my solution? Will it work?
Thanks for your input.
triggers work abysmally over a network, let alone a wan.
Hilary Cotter
Looking for a SQL Server replication book?
http://www.nwsu.com/0974973602.html
Looking for a FAQ on Indexing Services/SQL FTS
http://www.indexserverfaq.com
"daveberm" <david.bermingham@.steeleye.com> wrote in message
news:1172767518.597593.64730@.8g2000cwh.googlegroup s.com...
>I have a customer who has about 80 SQL 2005 servers in remote offices
> with various WAN links. The distribution of the SQL servers are as
> follows:
> - 15 site servers (publishers) must update to a single regional server
> (central subscriber), there are about 5 regional servers, each with
> their own set of publishers, for a total of about 75 publishers and 5
> subscribers.
> - There is a single SQL server in central HQ which must get updates
> from all of the regional servers, for a complete picture of all the
> data from the site servers.
> - The amount of updates at each site are minimal and only occur once
> or twice per day. However, when the update does occur, it should be
> pushed out with minimal delay to the regional server as well as the
> central HQ server.
> - The data at the regional and HQ locations must be available at all
> times for reporting purposes. No updates will be performed at the
> regional or HQ locations.
> - SQL Transactional Replication in a central subscriber model has been
> investigated as a possible solution, but has been eliminated as a
> possibility at this time for various reasons.
> What am considering is a solution similar to the following.
> Create a Trigger (http://msdn2.microsoft.com/en-us/library/
> ms189799.aspx) that automatically updates a linked server upon update
> of a table or view at the site server. Each site office would have a
> linked server back to the SQL server in the regional office as well as
> the SQL server in the central HQ office. This would ensure that each
> time the data is updated, it is automatically updated on the remote
> servers as well.
> Any thoughts on my solution? Will it work?
> Thanks for your input.
>
|||On Mar 2, 9:59 pm, "Hilary Cotter" <hilary.cot...@.gmail.com> wrote:
> triggers work abysmally over a network, let alone a wan.
> --
> Hilary Cotter
> Looking for a SQL Server replication book?http://www.nwsu.com/0974973602.html
> Looking for a FAQ on Indexing Services/SQL FTShttp://www.indexserverfaq.com
> "daveberm" <david.berming...@.steeleye.com> wrote in message
> news:1172767518.597593.64730@.8g2000cwh.googlegroup s.com...
>
>
>
>
>
>
> - Show quoted text -
Thanks Hilary. I'm in no way a Transact SQL guru, so please forgive
my ignorance. Here is the logic I was considering...
If a local table is updated, have a trigger that detects that update
and runs an INSERT query to update a linked table, which is on the
other side of a WAN.
So here are some more questions...
Is it the INSERT to the linked table that is abysmal? Assuming the
link is stable, is it just that it is slow or are there other issues?
I suppose any update to a linked table across a WAN is abysmal,
regardless of whether it is run by a trigger or by the application
itself, would you agree?
Does transactional replication address the performance issues of
updates over a WAN, or does it suffer from he same restraints?
What if it is just a very small transaction, say just an INSERT of a
single row that occures 2-3 times a day, do you still have
reservations about that kind of implementation over a WAN?
So given my situation, 15 sites with databases that need to update
small amounts of data 2-3 times a day to a master database (for
reporting purposes) across WAN links, what would you recommend?
And finally, are you available on a consulting basis? If so, I may
need your assistance if things get hairy.
David A. Bermingham, MCSE, MCSA:Messaging
Director of Product Management
www.steeleye.com
|||Hi Dave!
Basically the insert is wrapped in a transaction when you fire a trigger.
Any update done over a network incurs network hop which will add latency to
all transactions. For example there is a replication topology called
immediate updating where precisely what you are trying to do is implemented.
For a client of mine we found that transaction latency increased from 50 ms
(average) to 150 ms average. Over a WAN you can imagine the increase in
latency.
The real problem is that if there is any network interruption the calling
transaction (which could be the trigger) will hang for up to 20 s before
giving you an access denied error message and rolling back the trigger and
the precipitating trigger action.
So, triggers over the network simply aren't scalable and seriously degrade
performance.
HTH
Hilary Cotter
Looking for a SQL Server replication book?
http://www.nwsu.com/0974973602.html
Looking for a FAQ on Indexing Services/SQL FTS
http://www.indexserverfaq.com
"daveberm" <david.bermingham@.steeleye.com> wrote in message
news:1172974417.463883.123990@.s48g2000cws.googlegr oups.com...
> On Mar 2, 9:59 pm, "Hilary Cotter" <hilary.cot...@.gmail.com> wrote:
> Thanks Hilary. I'm in no way a Transact SQL guru, so please forgive
> my ignorance. Here is the logic I was considering...
> If a local table is updated, have a trigger that detects that update
> and runs an INSERT query to update a linked table, which is on the
> other side of a WAN.
> So here are some more questions...
> Is it the INSERT to the linked table that is abysmal? Assuming the
> link is stable, is it just that it is slow or are there other issues?
> I suppose any update to a linked table across a WAN is abysmal,
> regardless of whether it is run by a trigger or by the application
> itself, would you agree?
> Does transactional replication address the performance issues of
> updates over a WAN, or does it suffer from he same restraints?
> What if it is just a very small transaction, say just an INSERT of a
> single row that occures 2-3 times a day, do you still have
> reservations about that kind of implementation over a WAN?
> So given my situation, 15 sites with databases that need to update
> small amounts of data 2-3 times a day to a master database (for
> reporting purposes) across WAN links, what would you recommend?
> And finally, are you available on a consulting basis? If so, I may
> need your assistance if things get hairy.
> David A. Bermingham, MCSE, MCSA:Messaging
> Director of Product Management
> www.steeleye.com
>
|||On Mar 5, 8:59 am, "Hilary Cotter" <hilary.cot...@.gmail.com> wrote:
> Hi Dave!
> Basically the insert is wrapped in a transaction when you fire a trigger.
> Any update done over a network incurs network hop which will add latency to
> all transactions. For example there is a replication topology called
> immediate updating where precisely what you are trying to do is implemented.
> For a client of mine we found that transaction latency increased from 50 ms
> (average) to 150 ms average. Over a WAN you can imagine the increase in
> latency.
> The real problem is that if there is any network interruption the calling
> transaction (which could be the trigger) will hang for up to 20 s before
> giving you an access denied error message and rolling back the trigger and
> the precipitating trigger action.
> So, triggers over the network simply aren't scalable and seriously degrade
> performance.
> HTH
> --
> Hilary Cotter
> Looking for a SQL Server replication book?http://www.nwsu.com/0974973602.html
> Looking for a FAQ on Indexing Services/SQL FTShttp://www.indexserverfaq.com
> "daveberm" <david.berming...@.steeleye.com> wrote in message
> news:1172974417.463883.123990@.s48g2000cws.googlegr oups.com...
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
> - Show quoted text -
Thanks Hilary.
How does Transactional Replication handle latency and instability of
WAN links? What happens to the replication if a link between
Publisger and Subscriber is down for a period of time? Is
Transactional Replication recommended when Publishers and Subscribers
are on the other side of WAN links?
In my case, data needs to be updated generally with 2-3 minutes of the
original update to the Publisher. Is Transaction Replication useful
in this case, considing WAN links are in place?
Thanks again for your insight.
Dave

Alternative to this clumsy effort?

I have a little problem that I think I solved with a sledge-hammer and
thought I'd post here to see if there was not perhaps a more elegant
and probably quicker solution.
Essentially I have a unique display condition on a table that must
return data in a certain way. The problem column in question is the
second col of a compound PK which thus makes the data in this column
unique for any given col1 value. The problem is that regardles of what
data is in col2, if one of the values is 'NO' ,then this MUST appear
at the top of any resultset, query, or report that can be generated,
otherwise standard alpha sort is fine (it is a varchar(30) field)
My inelegant solution was to create a third column in the table, a
char(1) that can only ever have 2 values, a '1' or a '0'. So all
entries for col2 which are 'NO' get assigned the value 1, all others
are 0 so when you sort using this extra column based on any col1
value, 'NO' always gets to go on top.

Can I lose the extra column which is there purely for sorting/logic
and thus is irrelevant to the table data or its meaning(<hangs head in
due deference to normalisation>) It obviously works OK the way it is,
but it makes all queries/sprocs cumbersome because they always have
the overhead of sorting an additioal column, or an inefficient index
where nearly all the values in a vital column are always '0' except te
odd few, also all the updates and inserts need to be wary of changes
or additions that are make a 'NO' value for col2 and thus reset or set
the sort column to a '1'.

Some sample DDL and values below.

CREATE TABLE [dbo].[tmpTest]
(
[colA] [varchar](30) COLLATE Latin1_General_CI_AS NOT NULL,
[colB] [varchar](30) COLLATE Latin1_General_CI_AS NOT NULL,
[colN] [varchar](50) COLLATE Latin1_General_CI_AS NULL CONSTRAINT
[DF__1] DEFAULT ('UNK'),
[Reference] [char](1) COLLATE Latin1_General_CI_AS NULL DEFAULT
('0'),
CONSTRAINT [PK_tmpText]
PRIMARY KEY CLUSTERED ([colA] asc , [colB] asc)
)
ON [PRIMARY]

insert into tmpTest (colA,colB,colN) values ('1','a','z')
insert into tmpTest (colA,colB,colN) values ('1','b','z')
insert into tmpTest (colA,colB,colN) values ('1','c','z')
insert into tmpTest (colA,colB,colN,reference) values
('2','NO','z','1')

insert into tmpTest (colA,colB,colN) values ('2','a','z')
insert into tmpTest (colA,colB,colN) values ('2','b','z')
insert into tmpTest (colA,colB,colN) values ('2','c','z')
insert into tmpTest (colA,colB,colN) values ('2','d','z')

select * from tmpTest
where colA='2'
order by colA,reference desc,colBYou can use a CASE expression to achieve the same result.

SELECT *
FROM tmpTest
WHERE colA='2'
ORDER BY colA,
CASE WHEN colB = 'NO' THEN 0 ELSE 1 END, colB

--
David Portas
SQL Server MVP
--

Alternative to textcopy.exe in SQL2005

We have been using the textcopy.exe tool since SQL7 (we were able to still
use this tool when we upgraded SQL2000) - we have a VB6 app that a user can
use to attach a file (a .pdf file or a .doc file, etc.) to a "job", or record
in our database. Basically, the VB6 code calls a stored proc and passes it
the name and location of the file. The stored proc will then use the
textcopy.exe to upload this file into an image column in a database table:
SET @.cmd = 'c:\MSSQL7\Binn\textcopy.exe /S SQL01/D DB01 /U username /P
password /T tblImages /C picture /W ' + @.whr + ' /F ' + @.fil + ' /' + @.mod
EXEC Master..xp_cmdShell @.cmd
where @.whr is the path (e.g. c:\folder\) and @.fil is the filename (e.g.
test.pdf).
When we upgraded from 7 to 2000, we could still use the textcopy.exe to do
this. I'm testing a 2000 to 2005 upgrade and I can't get the textcopy.exe to
work in 2005.
What is the best way to insert a file into an image column in the database
in 2005? I'd like to not have to re-architect this piece of our application,
but I may have to...is there an alternative similar to textcopy.exe for SQL
2005? Indexing the file is not important - we just need to save the file in
the database so that it can be viewed from a web application.
Thanks!
Jeff M.
One method is to insert the blob data using OPENROWSET...BULK and then
update your main table:
CREATE PROC dbo.UpdateMyTableImageData
@.MyPK int,
@.FileName varchar(255)
AS
DECLARE @.SqlStatement nvarchar(MAX)
CREATE TABLE #BlobData(BlobData varbinary(max))
--insert blob into temp table
SET @.SqlStatement =
N'
INSERT INTO #BlobData
SELECT BlobData.*
FROM OPENROWSET
(BULK ''' + @.FileName + ''',
SINGLE_BLOB) BlobData'
EXEC sp_executesql @.SqlStatement
--update main table with blob data
UPDATE dbo.MyTable
SET MyBlob = (SELECT BlobData FROM #BlobData)
WHERE MyTable.MyPK = @.MyPK
DROP TABLE #BlobData
GO
Personality, I think the file content should be inserted directly from your
client application rather than on the server.
Hope this helps.
Dan Guzman
SQL Server MVP
"jeffromiller" <jeffromiller@.discussions.microsoft.com> wrote in message
news:727F2AB3-AA04-44E2-9D44-4990C8B96097@.microsoft.com...
> We have been using the textcopy.exe tool since SQL7 (we were able to still
> use this tool when we upgraded SQL2000) - we have a VB6 app that a user
> can
> use to attach a file (a .pdf file or a .doc file, etc.) to a "job", or
> record
> in our database. Basically, the VB6 code calls a stored proc and passes
> it
> the name and location of the file. The stored proc will then use the
> textcopy.exe to upload this file into an image column in a database table:
> SET @.cmd = 'c:\MSSQL7\Binn\textcopy.exe /S SQL01/D DB01 /U username /P
> password /T tblImages /C picture /W ' + @.whr + ' /F ' + @.fil + ' /' + @.mod
> EXEC Master..xp_cmdShell @.cmd
> where @.whr is the path (e.g. c:\folder\) and @.fil is the filename (e.g.
> test.pdf).
> When we upgraded from 7 to 2000, we could still use the textcopy.exe to do
> this. I'm testing a 2000 to 2005 upgrade and I can't get the textcopy.exe
> to
> work in 2005.
> What is the best way to insert a file into an image column in the database
> in 2005? I'd like to not have to re-architect this piece of our
> application,
> but I may have to...is there an alternative similar to textcopy.exe for
> SQL
> 2005? Indexing the file is not important - we just need to save the file
> in
> the database so that it can be viewed from a web application.
> Thanks!
> Jeff M.
|||Thanks Dan - that most definitely points me in the right direction! And I
agree, at some point here in the near future we will certainly re-architect
the app to do the insert...but for now, we need to upgrade the DB first.
Thanks again!
Jeff M.
"Dan Guzman" wrote:

> One method is to insert the blob data using OPENROWSET...BULK and then
> update your main table:
> CREATE PROC dbo.UpdateMyTableImageData
> @.MyPK int,
> @.FileName varchar(255)
> AS
> DECLARE @.SqlStatement nvarchar(MAX)
> CREATE TABLE #BlobData(BlobData varbinary(max))
> --insert blob into temp table
> SET @.SqlStatement =
> N'
> INSERT INTO #BlobData
> SELECT BlobData.*
> FROM OPENROWSET
> (BULK ''' + @.FileName + ''',
> SINGLE_BLOB) BlobData'
> EXEC sp_executesql @.SqlStatement
> --update main table with blob data
> UPDATE dbo.MyTable
> SET MyBlob = (SELECT BlobData FROM #BlobData)
> WHERE MyTable.MyPK = @.MyPK
> DROP TABLE #BlobData
> GO
> Personality, I think the file content should be inserted directly from your
> client application rather than on the server.
> --
> Hope this helps.
> Dan Guzman
> SQL Server MVP
> "jeffromiller" <jeffromiller@.discussions.microsoft.com> wrote in message
> news:727F2AB3-AA04-44E2-9D44-4990C8B96097@.microsoft.com...
>
>

Alternative to textcopy.exe in SQL2005

We have been using the textcopy.exe tool since SQL7 (we were able to still
use this tool when we upgraded SQL2000) - we have a VB6 app that a user can
use to attach a file (a .pdf file or a .doc file, etc.) to a "job", or record
in our database. Basically, the VB6 code calls a stored proc and passes it
the name and location of the file. The stored proc will then use the
textcopy.exe to upload this file into an image column in a database table:
SET @.cmd = 'c:\MSSQL7\Binn\textcopy.exe /S SQL01/D DB01 /U username /P
password /T tblImages /C picture /W ' + @.whr + ' /F ' + @.fil + ' /' + @.mod
EXEC Master..xp_cmdShell @.cmd
where @.whr is the path (e.g. c:\folder\) and @.fil is the filename (e.g.
test.pdf).
When we upgraded from 7 to 2000, we could still use the textcopy.exe to do
this. I'm testing a 2000 to 2005 upgrade and I can't get the textcopy.exe to
work in 2005.
What is the best way to insert a file into an image column in the database
in 2005? I'd like to not have to re-architect this piece of our application,
but I may have to...is there an alternative similar to textcopy.exe for SQL
2005? Indexing the file is not important - we just need to save the file in
the database so that it can be viewed from a web application.
Thanks!
Jeff M.One method is to insert the blob data using OPENROWSET...BULK and then
update your main table:
CREATE PROC dbo.UpdateMyTableImageData
@.MyPK int,
@.FileName varchar(255)
AS
DECLARE @.SqlStatement nvarchar(MAX)
CREATE TABLE #BlobData(BlobData varbinary(max))
--insert blob into temp table
SET @.SqlStatement = N'
INSERT INTO #BlobData
SELECT BlobData.*
FROM OPENROWSET
(BULK ''' + @.FileName + ''',
SINGLE_BLOB) BlobData'
EXEC sp_executesql @.SqlStatement
--update main table with blob data
UPDATE dbo.MyTable
SET MyBlob = (SELECT BlobData FROM #BlobData)
WHERE MyTable.MyPK = @.MyPK
DROP TABLE #BlobData
GO
Personality, I think the file content should be inserted directly from your
client application rather than on the server.
--
Hope this helps.
Dan Guzman
SQL Server MVP
"jeffromiller" <jeffromiller@.discussions.microsoft.com> wrote in message
news:727F2AB3-AA04-44E2-9D44-4990C8B96097@.microsoft.com...
> We have been using the textcopy.exe tool since SQL7 (we were able to still
> use this tool when we upgraded SQL2000) - we have a VB6 app that a user
> can
> use to attach a file (a .pdf file or a .doc file, etc.) to a "job", or
> record
> in our database. Basically, the VB6 code calls a stored proc and passes
> it
> the name and location of the file. The stored proc will then use the
> textcopy.exe to upload this file into an image column in a database table:
> SET @.cmd = 'c:\MSSQL7\Binn\textcopy.exe /S SQL01/D DB01 /U username /P
> password /T tblImages /C picture /W ' + @.whr + ' /F ' + @.fil + ' /' + @.mod
> EXEC Master..xp_cmdShell @.cmd
> where @.whr is the path (e.g. c:\folder\) and @.fil is the filename (e.g.
> test.pdf).
> When we upgraded from 7 to 2000, we could still use the textcopy.exe to do
> this. I'm testing a 2000 to 2005 upgrade and I can't get the textcopy.exe
> to
> work in 2005.
> What is the best way to insert a file into an image column in the database
> in 2005? I'd like to not have to re-architect this piece of our
> application,
> but I may have to...is there an alternative similar to textcopy.exe for
> SQL
> 2005? Indexing the file is not important - we just need to save the file
> in
> the database so that it can be viewed from a web application.
> Thanks!
> Jeff M.|||Thanks Dan - that most definitely points me in the right direction! And I
agree, at some point here in the near future we will certainly re-architect
the app to do the insert...but for now, we need to upgrade the DB first.
Thanks again!
Jeff M.
"Dan Guzman" wrote:
> One method is to insert the blob data using OPENROWSET...BULK and then
> update your main table:
> CREATE PROC dbo.UpdateMyTableImageData
> @.MyPK int,
> @.FileName varchar(255)
> AS
> DECLARE @.SqlStatement nvarchar(MAX)
> CREATE TABLE #BlobData(BlobData varbinary(max))
> --insert blob into temp table
> SET @.SqlStatement => N'
> INSERT INTO #BlobData
> SELECT BlobData.*
> FROM OPENROWSET
> (BULK ''' + @.FileName + ''',
> SINGLE_BLOB) BlobData'
> EXEC sp_executesql @.SqlStatement
> --update main table with blob data
> UPDATE dbo.MyTable
> SET MyBlob = (SELECT BlobData FROM #BlobData)
> WHERE MyTable.MyPK = @.MyPK
> DROP TABLE #BlobData
> GO
> Personality, I think the file content should be inserted directly from your
> client application rather than on the server.
> --
> Hope this helps.
> Dan Guzman
> SQL Server MVP
> "jeffromiller" <jeffromiller@.discussions.microsoft.com> wrote in message
> news:727F2AB3-AA04-44E2-9D44-4990C8B96097@.microsoft.com...
> > We have been using the textcopy.exe tool since SQL7 (we were able to still
> > use this tool when we upgraded SQL2000) - we have a VB6 app that a user
> > can
> > use to attach a file (a .pdf file or a .doc file, etc.) to a "job", or
> > record
> > in our database. Basically, the VB6 code calls a stored proc and passes
> > it
> > the name and location of the file. The stored proc will then use the
> > textcopy.exe to upload this file into an image column in a database table:
> >
> > SET @.cmd = 'c:\MSSQL7\Binn\textcopy.exe /S SQL01/D DB01 /U username /P
> > password /T tblImages /C picture /W ' + @.whr + ' /F ' + @.fil + ' /' + @.mod
> >
> > EXEC Master..xp_cmdShell @.cmd
> >
> > where @.whr is the path (e.g. c:\folder\) and @.fil is the filename (e.g.
> > test.pdf).
> >
> > When we upgraded from 7 to 2000, we could still use the textcopy.exe to do
> > this. I'm testing a 2000 to 2005 upgrade and I can't get the textcopy.exe
> > to
> > work in 2005.
> >
> > What is the best way to insert a file into an image column in the database
> > in 2005? I'd like to not have to re-architect this piece of our
> > application,
> > but I may have to...is there an alternative similar to textcopy.exe for
> > SQL
> > 2005? Indexing the file is not important - we just need to save the file
> > in
> > the database so that it can be viewed from a web application.
> >
> > Thanks!
> > Jeff M.
>
>

Alternative to textcopy.exe in SQL2005

We have been using the textcopy.exe tool since SQL7 (we were able to still
use this tool when we upgraded SQL2000) - we have a VB6 app that a user can
use to attach a file (a .pdf file or a .doc file, etc.) to a "job", or recor
d
in our database. Basically, the VB6 code calls a stored proc and passes it
the name and location of the file. The stored proc will then use the
textcopy.exe to upload this file into an image column in a database table:
SET @.cmd = 'c:\MSSQL7\Binn\textcopy.exe /S SQL01/D DB01 /U username /P
password /T tblImages /C picture /W ' + @.whr + ' /F ' + @.fil + ' /' + @.mod
EXEC Master..xp_cmdShell @.cmd
where @.whr is the path (e.g. c:\folder\) and @.fil is the filename (e.g.
test.pdf).
When we upgraded from 7 to 2000, we could still use the textcopy.exe to do
this. I'm testing a 2000 to 2005 upgrade and I can't get the textcopy.exe t
o
work in 2005.
What is the best way to insert a file into an image column in the database
in 2005? I'd like to not have to re-architect this piece of our application
,
but I may have to...is there an alternative similar to textcopy.exe for SQL
2005? Indexing the file is not important - we just need to save the file in
the database so that it can be viewed from a web application.
Thanks!
Jeff M.One method is to insert the blob data using OPENROWSET...BULK and then
update your main table:
CREATE PROC dbo.UpdateMyTableImageData
@.MyPK int,
@.FileName varchar(255)
AS
DECLARE @.SqlStatement nvarchar(MAX)
CREATE TABLE #BlobData(BlobData varbinary(max))
--insert blob into temp table
SET @.SqlStatement =
N'
INSERT INTO #BlobData
SELECT BlobData.*
FROM OPENROWSET
(BULK ''' + @.FileName + ''',
SINGLE_BLOB) BlobData'
EXEC sp_executesql @.SqlStatement
--update main table with blob data
UPDATE dbo.MyTable
SET MyBlob = (SELECT BlobData FROM #BlobData)
WHERE MyTable.MyPK = @.MyPK
DROP TABLE #BlobData
GO
Personality, I think the file content should be inserted directly from your
client application rather than on the server.
Hope this helps.
Dan Guzman
SQL Server MVP
"jeffromiller" <jeffromiller@.discussions.microsoft.com> wrote in message
news:727F2AB3-AA04-44E2-9D44-4990C8B96097@.microsoft.com...
> We have been using the textcopy.exe tool since SQL7 (we were able to still
> use this tool when we upgraded SQL2000) - we have a VB6 app that a user
> can
> use to attach a file (a .pdf file or a .doc file, etc.) to a "job", or
> record
> in our database. Basically, the VB6 code calls a stored proc and passes
> it
> the name and location of the file. The stored proc will then use the
> textcopy.exe to upload this file into an image column in a database table:
> SET @.cmd = 'c:\MSSQL7\Binn\textcopy.exe /S SQL01/D DB01 /U username /P
> password /T tblImages /C picture /W ' + @.whr + ' /F ' + @.fil + ' /' + @.mod
> EXEC Master..xp_cmdShell @.cmd
> where @.whr is the path (e.g. c:\folder\) and @.fil is the filename (e.g.
> test.pdf).
> When we upgraded from 7 to 2000, we could still use the textcopy.exe to do
> this. I'm testing a 2000 to 2005 upgrade and I can't get the textcopy.exe
> to
> work in 2005.
> What is the best way to insert a file into an image column in the database
> in 2005? I'd like to not have to re-architect this piece of our
> application,
> but I may have to...is there an alternative similar to textcopy.exe for
> SQL
> 2005? Indexing the file is not important - we just need to save the file
> in
> the database so that it can be viewed from a web application.
> Thanks!
> Jeff M.|||Thanks Dan - that most definitely points me in the right direction! And I
agree, at some point here in the near future we will certainly re-architect
the app to do the insert...but for now, we need to upgrade the DB first.
Thanks again!
Jeff M.
"Dan Guzman" wrote:

> One method is to insert the blob data using OPENROWSET...BULK and then
> update your main table:
> CREATE PROC dbo.UpdateMyTableImageData
> @.MyPK int,
> @.FileName varchar(255)
> AS
> DECLARE @.SqlStatement nvarchar(MAX)
> CREATE TABLE #BlobData(BlobData varbinary(max))
> --insert blob into temp table
> SET @.SqlStatement =
> N'
> INSERT INTO #BlobData
> SELECT BlobData.*
> FROM OPENROWSET
> (BULK ''' + @.FileName + ''',
> SINGLE_BLOB) BlobData'
> EXEC sp_executesql @.SqlStatement
> --update main table with blob data
> UPDATE dbo.MyTable
> SET MyBlob = (SELECT BlobData FROM #BlobData)
> WHERE MyTable.MyPK = @.MyPK
> DROP TABLE #BlobData
> GO
> Personality, I think the file content should be inserted directly from you
r
> client application rather than on the server.
> --
> Hope this helps.
> Dan Guzman
> SQL Server MVP
> "jeffromiller" <jeffromiller@.discussions.microsoft.com> wrote in message
> news:727F2AB3-AA04-44E2-9D44-4990C8B96097@.microsoft.com...
>
>

Alternative to Temporary table to store stored procedure results

I have come across the error "INSERT EXEC statement cannot be nested"
when trying to store the results of a stored procedure in a temporary
table. I understand why this is happening - because there is already
an INSERT EXEC in the stored procedure I am executing - but I need to
be able to store the results in some way.
Unfortunately re-writing the stored procedure I am calling is not an
option, and I was wondering if there is another way for me to evaluate
the results from my stored procedure.
I have looked into table variables and functions, but they do not work
here either.
I would appreciate anyone's input on this.
Are you refering to something like this:
USE PUBS
GO
CREATE PROC USP_TEMPPROC
AS
CREATE TABLE #TEST1 (AU_ID VARCHAR(25))
CREATE TABLE #TEST2 (AU_ID VARCHAR(25))
INSERT #TEST1
EXEC BYROYALTY 100
SELECT * FROM #TEST1
INSERT #TEST2
EXEC BYROYALTY 100
SELECT * FROM #TEST2
DROP TABLE #TEST1
DROP TABLE #TEST2
EXEC USP_TEMPPROC
--OR SOMETHING LIKE THIS:
USE PUBS
GO
CREATE PROC USP_TEMPPROC_2A
AS
CREATE TABLE #TEST1 (AU_ID VARCHAR(25))
INSERT #TEST1
EXEC BYROYALTY 100
SELECT * FROM #TEST1
EXEC USP_TEMPPROC_2B
DROP TABLE #TEST1
CREATE PROC USP_TEMPPROC_2B
AS
CREATE TABLE #TEST2 (AU_ID VARCHAR(25))
INSERT #TEST2
EXEC BYROYALTY 100
SELECT * FROM #TEST2
DROP TABLE #TEST2
EXEC USP_TEMPPROC_2A
Both seem to work.
HTH
Jerry
<c.williamson@.dialaphone.com> wrote in message
news:1128098603.949372.70830@.z14g2000cwz.googlegro ups.com...
>I have come across the error "INSERT EXEC statement cannot be nested"
> when trying to store the results of a stored procedure in a temporary
> table. I understand why this is happening - because there is already
> an INSERT EXEC in the stored procedure I am executing - but I need to
> be able to store the results in some way.
> Unfortunately re-writing the stored procedure I am calling is not an
> option, and I was wondering if there is another way for me to evaluate
> the results from my stored procedure.
> I have looked into table variables and functions, but they do not work
> here either.
> I would appreciate anyone's input on this.
>
|||More like the second example, but slightly different:
USE PUBS
GO
CREATE PROC USP_TEMPPROC_2A
AS
CREATE TABLE #TEST1 (AU_ID VARCHAR(25))
INSERT #TEST1
EXEC USP_TEMPPROC_2B
DROP TABLE #TEST1
CREATE PROC USP_TEMPPROC_2B
AS
CREATE TABLE #TEST2 (AU_ID VARCHAR(25))
INSERT #TEST2
EXEC BYROYALTY 100
SELECT * FROM #TEST2
DROP TABLE #TEST2
EXEC USP_TEMPPROC_2A
When running the last line I get "An INSERT EXEC statement cannot be
nested", because in both stored procedures I am trying to store results
from the sp in a temporary table.
I cannot re-write the second stored procedure, so I need some way to
work with the results in the first stored procedure.
Thank you
Christian
Jerry Spivey wrote:[vbcol=seagreen]
> Are you refering to something like this:
> USE PUBS
> GO
> CREATE PROC USP_TEMPPROC
> AS
> CREATE TABLE #TEST1 (AU_ID VARCHAR(25))
> CREATE TABLE #TEST2 (AU_ID VARCHAR(25))
> INSERT #TEST1
> EXEC BYROYALTY 100
> SELECT * FROM #TEST1
> INSERT #TEST2
> EXEC BYROYALTY 100
> SELECT * FROM #TEST2
> DROP TABLE #TEST1
> DROP TABLE #TEST2
> EXEC USP_TEMPPROC
> --OR SOMETHING LIKE THIS:
> USE PUBS
> GO
> CREATE PROC USP_TEMPPROC_2A
> AS
> CREATE TABLE #TEST1 (AU_ID VARCHAR(25))
> INSERT #TEST1
> EXEC BYROYALTY 100
> SELECT * FROM #TEST1
> EXEC USP_TEMPPROC_2B
> DROP TABLE #TEST1
> CREATE PROC USP_TEMPPROC_2B
> AS
> CREATE TABLE #TEST2 (AU_ID VARCHAR(25))
> INSERT #TEST2
> EXEC BYROYALTY 100
> SELECT * FROM #TEST2
> DROP TABLE #TEST2
> EXEC USP_TEMPPROC_2A
> Both seem to work.
> HTH
> Jerry
> <c.williamson@.dialaphone.com> wrote in message
> news:1128098603.949372.70830@.z14g2000cwz.googlegro ups.com...

Alternative to Temporary table to store stored procedure results

I have come across the error "INSERT EXEC statement cannot be nested"
when trying to store the results of a stored procedure in a temporary
table. I understand why this is happening - because there is already
an INSERT EXEC in the stored procedure I am executing - but I need to
be able to store the results in some way.
Unfortunately re-writing the stored procedure I am calling is not an
option, and I was wondering if there is another way for me to evaluate
the results from my stored procedure.
I have looked into table variables and functions, but they do not work
here either.
I would appreciate anyone's input on this.Are you refering to something like this:
USE PUBS
GO
CREATE PROC USP_TEMPPROC
AS
CREATE TABLE #TEST1 (AU_ID VARCHAR(25))
CREATE TABLE #TEST2 (AU_ID VARCHAR(25))
INSERT #TEST1
EXEC BYROYALTY 100
SELECT * FROM #TEST1
INSERT #TEST2
EXEC BYROYALTY 100
SELECT * FROM #TEST2
DROP TABLE #TEST1
DROP TABLE #TEST2
EXEC USP_TEMPPROC
--OR SOMETHING LIKE THIS:
USE PUBS
GO
CREATE PROC USP_TEMPPROC_2A
AS
CREATE TABLE #TEST1 (AU_ID VARCHAR(25))
INSERT #TEST1
EXEC BYROYALTY 100
SELECT * FROM #TEST1
EXEC USP_TEMPPROC_2B
DROP TABLE #TEST1
CREATE PROC USP_TEMPPROC_2B
AS
CREATE TABLE #TEST2 (AU_ID VARCHAR(25))
INSERT #TEST2
EXEC BYROYALTY 100
SELECT * FROM #TEST2
DROP TABLE #TEST2
EXEC USP_TEMPPROC_2A
Both seem to work.
HTH
Jerry
<c.williamson@.dialaphone.com> wrote in message
news:1128098603.949372.70830@.z14g2000cwz.googlegroups.com...
>I have come across the error "INSERT EXEC statement cannot be nested"
> when trying to store the results of a stored procedure in a temporary
> table. I understand why this is happening - because there is already
> an INSERT EXEC in the stored procedure I am executing - but I need to
> be able to store the results in some way.
> Unfortunately re-writing the stored procedure I am calling is not an
> option, and I was wondering if there is another way for me to evaluate
> the results from my stored procedure.
> I have looked into table variables and functions, but they do not work
> here either.
> I would appreciate anyone's input on this.
>|||More like the second example, but slightly different:
USE PUBS
GO
CREATE PROC USP_TEMPPROC_2A
AS
CREATE TABLE #TEST1 (AU_ID VARCHAR(25))
INSERT #TEST1
EXEC USP_TEMPPROC_2B
DROP TABLE #TEST1
CREATE PROC USP_TEMPPROC_2B
AS
CREATE TABLE #TEST2 (AU_ID VARCHAR(25))
INSERT #TEST2
EXEC BYROYALTY 100
SELECT * FROM #TEST2
DROP TABLE #TEST2
EXEC USP_TEMPPROC_2A
When running the last line I get "An INSERT EXEC statement cannot be
nested", because in both stored procedures I am trying to store results
from the sp in a temporary table.
I cannot re-write the second stored procedure, so I need some way to
work with the results in the first stored procedure.
Thank you
Christian
Jerry Spivey wrote:[vbcol=seagreen]
> Are you refering to something like this:
> USE PUBS
> GO
> CREATE PROC USP_TEMPPROC
> AS
> CREATE TABLE #TEST1 (AU_ID VARCHAR(25))
> CREATE TABLE #TEST2 (AU_ID VARCHAR(25))
> INSERT #TEST1
> EXEC BYROYALTY 100
> SELECT * FROM #TEST1
> INSERT #TEST2
> EXEC BYROYALTY 100
> SELECT * FROM #TEST2
> DROP TABLE #TEST1
> DROP TABLE #TEST2
> EXEC USP_TEMPPROC
> --OR SOMETHING LIKE THIS:
> USE PUBS
> GO
> CREATE PROC USP_TEMPPROC_2A
> AS
> CREATE TABLE #TEST1 (AU_ID VARCHAR(25))
> INSERT #TEST1
> EXEC BYROYALTY 100
> SELECT * FROM #TEST1
> EXEC USP_TEMPPROC_2B
> DROP TABLE #TEST1
> CREATE PROC USP_TEMPPROC_2B
> AS
> CREATE TABLE #TEST2 (AU_ID VARCHAR(25))
> INSERT #TEST2
> EXEC BYROYALTY 100
> SELECT * FROM #TEST2
> DROP TABLE #TEST2
> EXEC USP_TEMPPROC_2A
> Both seem to work.
> HTH
> Jerry
> <c.williamson@.dialaphone.com> wrote in message
> news:1128098603.949372.70830@.z14g2000cwz.googlegroups.com...

Alternative to Temporary table to store stored procedure results

I have come across the error "INSERT EXEC statement cannot be nested"
when trying to store the results of a stored procedure in a temporary
table. I understand why this is happening - because there is already
an INSERT EXEC in the stored procedure I am executing - but I need to
be able to store the results in some way.
Unfortunately re-writing the stored procedure I am calling is not an
option, and I was wondering if there is another way for me to evaluate
the results from my stored procedure.
I have looked into table variables and functions, but they do not work
here either.
I would appreciate anyone's input on this.Are you refering to something like this:
USE PUBS
GO
CREATE PROC USP_TEMPPROC
AS
CREATE TABLE #TEST1 (AU_ID VARCHAR(25))
CREATE TABLE #TEST2 (AU_ID VARCHAR(25))
INSERT #TEST1
EXEC BYROYALTY 100
SELECT * FROM #TEST1
INSERT #TEST2
EXEC BYROYALTY 100
SELECT * FROM #TEST2
DROP TABLE #TEST1
DROP TABLE #TEST2
EXEC USP_TEMPPROC
--OR SOMETHING LIKE THIS:
USE PUBS
GO
CREATE PROC USP_TEMPPROC_2A
AS
CREATE TABLE #TEST1 (AU_ID VARCHAR(25))
INSERT #TEST1
EXEC BYROYALTY 100
SELECT * FROM #TEST1
EXEC USP_TEMPPROC_2B
DROP TABLE #TEST1
CREATE PROC USP_TEMPPROC_2B
AS
CREATE TABLE #TEST2 (AU_ID VARCHAR(25))
INSERT #TEST2
EXEC BYROYALTY 100
SELECT * FROM #TEST2
DROP TABLE #TEST2
EXEC USP_TEMPPROC_2A
Both seem to work.
HTH
Jerry
<c.williamson@.dialaphone.com> wrote in message
news:1128098603.949372.70830@.z14g2000cwz.googlegroups.com...
>I have come across the error "INSERT EXEC statement cannot be nested"
> when trying to store the results of a stored procedure in a temporary
> table. I understand why this is happening - because there is already
> an INSERT EXEC in the stored procedure I am executing - but I need to
> be able to store the results in some way.
> Unfortunately re-writing the stored procedure I am calling is not an
> option, and I was wondering if there is another way for me to evaluate
> the results from my stored procedure.
> I have looked into table variables and functions, but they do not work
> here either.
> I would appreciate anyone's input on this.
>|||More like the second example, but slightly different:
USE PUBS
GO
CREATE PROC USP_TEMPPROC_2A
AS
CREATE TABLE #TEST1 (AU_ID VARCHAR(25))
INSERT #TEST1
EXEC USP_TEMPPROC_2B
DROP TABLE #TEST1
CREATE PROC USP_TEMPPROC_2B
AS
CREATE TABLE #TEST2 (AU_ID VARCHAR(25))
INSERT #TEST2
EXEC BYROYALTY 100
SELECT * FROM #TEST2
DROP TABLE #TEST2
EXEC USP_TEMPPROC_2A
When running the last line I get "An INSERT EXEC statement cannot be
nested", because in both stored procedures I am trying to store results
from the sp in a temporary table.
I cannot re-write the second stored procedure, so I need some way to
work with the results in the first stored procedure.
Thank you
Christian
Jerry Spivey wrote:
> Are you refering to something like this:
> USE PUBS
> GO
> CREATE PROC USP_TEMPPROC
> AS
> CREATE TABLE #TEST1 (AU_ID VARCHAR(25))
> CREATE TABLE #TEST2 (AU_ID VARCHAR(25))
> INSERT #TEST1
> EXEC BYROYALTY 100
> SELECT * FROM #TEST1
> INSERT #TEST2
> EXEC BYROYALTY 100
> SELECT * FROM #TEST2
> DROP TABLE #TEST1
> DROP TABLE #TEST2
> EXEC USP_TEMPPROC
> --OR SOMETHING LIKE THIS:
> USE PUBS
> GO
> CREATE PROC USP_TEMPPROC_2A
> AS
> CREATE TABLE #TEST1 (AU_ID VARCHAR(25))
> INSERT #TEST1
> EXEC BYROYALTY 100
> SELECT * FROM #TEST1
> EXEC USP_TEMPPROC_2B
> DROP TABLE #TEST1
> CREATE PROC USP_TEMPPROC_2B
> AS
> CREATE TABLE #TEST2 (AU_ID VARCHAR(25))
> INSERT #TEST2
> EXEC BYROYALTY 100
> SELECT * FROM #TEST2
> DROP TABLE #TEST2
> EXEC USP_TEMPPROC_2A
> Both seem to work.
> HTH
> Jerry
> <c.williamson@.dialaphone.com> wrote in message
> news:1128098603.949372.70830@.z14g2000cwz.googlegroups.com...
> >I have come across the error "INSERT EXEC statement cannot be nested"
> > when trying to store the results of a stored procedure in a temporary
> > table. I understand why this is happening - because there is already
> > an INSERT EXEC in the stored procedure I am executing - but I need to
> > be able to store the results in some way.
> >
> > Unfortunately re-writing the stored procedure I am calling is not an
> > option, and I was wondering if there is another way for me to evaluate
> > the results from my stored procedure.
> >
> > I have looked into table variables and functions, but they do not work
> > here either.
> >
> > I would appreciate anyone's input on this.
> >

Alternative to SQL Server Management Studio?

Not sure that all of these are working in 2005, or even that they all still
exist. But a good portion should.
http://sqlserver2000.databases.aspfaq.com/how-do-i-manage-sql-server/msde.html
Aaron Bertrand
SQL Server MVP
http://www.sqlblog.com/
http://www.aspfaq.com/5006
<pshroads@.gmail.com> wrote in message
news:1180474299.187491.174550@.j4g2000prf.googlegro ups.com...
> Does anyone have any suggestions for 3rd party tools to replace SQL
> Server Management Studio. SMS is such bloatware and lacks so many nice
> features of Enterprise Manager that there must be some decent tools
> out there to use instead. I know there's Microsoft SQL Server
> Management Studio Express but it doesn't manage SQL Server Agent.
> Thanks!
>
I am partial to ApexSQL Edit for development (AMAZING range of features,
with incredible developer support/involvment). I use DBArtisan for admin,
but have been disappointed with their quality the last few years. WAY too
many bugs and 'special features', IMHO. However, if you are a
multi-platform shop Embarcadero is probably THE way to go.
TheSQLGuru
President
Indicium Resources, Inc.
"Aaron Bertrand [SQL Server MVP]" <ten.xoc@.dnartreb.noraa> wrote in message
news:OYigWukoHHA.716@.TK2MSFTNGP05.phx.gbl...
> Not sure that all of these are working in 2005, or even that they all
> still exist. But a good portion should.
> http://sqlserver2000.databases.aspfaq.com/how-do-i-manage-sql-server/msde.html
> --
> Aaron Bertrand
> SQL Server MVP
> http://www.sqlblog.com/
> http://www.aspfaq.com/5006
>
>
> <pshroads@.gmail.com> wrote in message
> news:1180474299.187491.174550@.j4g2000prf.googlegro ups.com...
>

Alternative to sp_delete_Backuphistory

I have a SQL 2000 server that has 300 databases. There is a requirement tha
t
these databases have their logs backed up every 30 minutes. This creates a
huge number of entries in the backup/restore tables in the msdb database.
I know I can delete backup history with the sp_delete_backuphistory command.
However, this command takes forever. Even deleting 30 minutes worth of
backups takes 15 or more minutes. I find I am creating entries in the
backup/restore tables faster than I could possible delete them.
Is there an alteranate way to clear out the backup/restore tables? Could is
simply truncate the tables?
Thanks for any info.
LehrSJYes, I ran into the same problem when I discovered the backup tables in
msdb were HUGE... instead of running the sp, I just truncated. The only
thing you lose by doing this is the ability to use Enterprise Manager
of Mgmt Studio to do your restore, as it relies on the information in
those tables when suggesting which backups to apply. If you can afford
to lose this, no big deal. The information will just get repopulated on
your next backups.
Also, once the tables are empty, set up a nightly job to run the
sp_delete_backuphistory, keep as many days worth of history as you
specify.
LehrSJ wrote:
> I have a SQL 2000 server that has 300 databases. There is a requirement t
hat
> these databases have their logs backed up every 30 minutes. This creates
a
> huge number of entries in the backup/restore tables in the msdb database.
> I know I can delete backup history with the sp_delete_backuphistory comman
d.
> However, this command takes forever. Even deleting 30 minutes worth of
> backups takes 15 or more minutes. I find I am creating entries in the
> backup/restore tables faster than I could possible delete them.
> Is there an alteranate way to clear out the backup/restore tables? Could
is
> simply truncate the tables?
> Thanks for any info.
> --
> LehrSJ|||Yes, you can truncate the tables. See the system table map to see the
relationships btwn the backup tables as there are dependencies between
them. All you lose by truncating the tables is the ability to use EM or
Mgmt Studio to do a restore, as it relies on the information in those
tables when suggesting which backups to apply. If you can afford to
lose it, no big deal. The information just gets repopluated on your
next backup.
Meanwhile, you might want to set up a nightly job to run
sp_delete_backuphistory so the table growth is kept in check.
LehrSJ wrote:
> I have a SQL 2000 server that has 300 databases. There is a requirement t
hat
> these databases have their logs backed up every 30 minutes. This creates
a
> huge number of entries in the backup/restore tables in the msdb database.
> I know I can delete backup history with the sp_delete_backuphistory comman
d.
> However, this command takes forever. Even deleting 30 minutes worth of
> backups takes 15 or more minutes. I find I am creating entries in the
> backup/restore tables faster than I could possible delete them.
> Is there an alteranate way to clear out the backup/restore tables? Could
is
> simply truncate the tables?
> Thanks for any info.
> --
> LehrSJ|||LehrSJ wrote:
> I have a SQL 2000 server that has 300 databases. There is a requirement t
hat
> these databases have their logs backed up every 30 minutes. This creates
a
> huge number of entries in the backup/restore tables in the msdb database.
> I know I can delete backup history with the sp_delete_backuphistory comman
d.
> However, this command takes forever. Even deleting 30 minutes worth of
> backups takes 15 or more minutes. I find I am creating entries in the
> backup/restore tables faster than I could possible delete them.
> Is there an alteranate way to clear out the backup/restore tables? Could
is
> simply truncate the tables?
> Thanks for any info.
>
The problem is that there are no useful indexes on the backup history
tables. Create these indexes, then sp_delete_backuphistory will fly:
CREATE INDEX IDX_temp on restorefile ( restore_history_id )
CREATE INDEX IDX_temp on restorefilegroup ( restore_history_id )
CREATE INDEX IDX_temp on backupset ( backup_finish_date )
CREATE INDEX IDX_temp2 ON backupset ( media_set_id )
Tracy McKibben
MCDBA
http://www.realsqlguy.com|||Thank you for this information. I didn't see why I couldn't truncate but I
was worried that there might be something that I didn't know about. I
understand what I will lose the ability for Enterprise manager to easily do
restores.
--
LehrSJ
"tootsuite@.gmail.com" wrote:

> Yes, you can truncate the tables. See the system table map to see the
> relationships btwn the backup tables as there are dependencies between
> them. All you lose by truncating the tables is the ability to use EM or
> Mgmt Studio to do a restore, as it relies on the information in those
> tables when suggesting which backups to apply. If you can afford to
> lose it, no big deal. The information just gets repopluated on your
> next backup.
> Meanwhile, you might want to set up a nightly job to run
> sp_delete_backuphistory so the table growth is kept in check.
> LehrSJ wrote:
>

Alternative to sp_delete_Backuphistory

I have a SQL 2000 server that has 300 databases. There is a requirement that
these databases have their logs backed up every 30 minutes. This creates a
huge number of entries in the backup/restore tables in the msdb database.
I know I can delete backup history with the sp_delete_backuphistory command.
However, this command takes forever. Even deleting 30 minutes worth of
backups takes 15 or more minutes. I find I am creating entries in the
backup/restore tables faster than I could possible delete them.
Is there an alteranate way to clear out the backup/restore tables? Could is
simply truncate the tables?
Thanks for any info.
LehrSJ
Yes, I ran into the same problem when I discovered the backup tables in
msdb were HUGE... instead of running the sp, I just truncated. The only
thing you lose by doing this is the ability to use Enterprise Manager
of Mgmt Studio to do your restore, as it relies on the information in
those tables when suggesting which backups to apply. If you can afford
to lose this, no big deal. The information will just get repopulated on
your next backups.
Also, once the tables are empty, set up a nightly job to run the
sp_delete_backuphistory, keep as many days worth of history as you
specify.
LehrSJ wrote:
> I have a SQL 2000 server that has 300 databases. There is a requirement that
> these databases have their logs backed up every 30 minutes. This creates a
> huge number of entries in the backup/restore tables in the msdb database.
> I know I can delete backup history with the sp_delete_backuphistory command.
> However, this command takes forever. Even deleting 30 minutes worth of
> backups takes 15 or more minutes. I find I am creating entries in the
> backup/restore tables faster than I could possible delete them.
> Is there an alteranate way to clear out the backup/restore tables? Could is
> simply truncate the tables?
> Thanks for any info.
> --
> LehrSJ
|||Yes, you can truncate the tables. See the system table map to see the
relationships btwn the backup tables as there are dependencies between
them. All you lose by truncating the tables is the ability to use EM or
Mgmt Studio to do a restore, as it relies on the information in those
tables when suggesting which backups to apply. If you can afford to
lose it, no big deal. The information just gets repopluated on your
next backup.
Meanwhile, you might want to set up a nightly job to run
sp_delete_backuphistory so the table growth is kept in check.
LehrSJ wrote:
> I have a SQL 2000 server that has 300 databases. There is a requirement that
> these databases have their logs backed up every 30 minutes. This creates a
> huge number of entries in the backup/restore tables in the msdb database.
> I know I can delete backup history with the sp_delete_backuphistory command.
> However, this command takes forever. Even deleting 30 minutes worth of
> backups takes 15 or more minutes. I find I am creating entries in the
> backup/restore tables faster than I could possible delete them.
> Is there an alteranate way to clear out the backup/restore tables? Could is
> simply truncate the tables?
> Thanks for any info.
> --
> LehrSJ
|||LehrSJ wrote:
> I have a SQL 2000 server that has 300 databases. There is a requirement that
> these databases have their logs backed up every 30 minutes. This creates a
> huge number of entries in the backup/restore tables in the msdb database.
> I know I can delete backup history with the sp_delete_backuphistory command.
> However, this command takes forever. Even deleting 30 minutes worth of
> backups takes 15 or more minutes. I find I am creating entries in the
> backup/restore tables faster than I could possible delete them.
> Is there an alteranate way to clear out the backup/restore tables? Could is
> simply truncate the tables?
> Thanks for any info.
>
The problem is that there are no useful indexes on the backup history
tables. Create these indexes, then sp_delete_backuphistory will fly:
CREATE INDEX IDX_temp on restorefile ( restore_history_id )
CREATE INDEX IDX_temp on restorefilegroup ( restore_history_id )
CREATE INDEX IDX_temp on backupset ( backup_finish_date )
CREATE INDEX IDX_temp2 ON backupset ( media_set_id )
Tracy McKibben
MCDBA
http://www.realsqlguy.com
|||Thank you for this information. I didn't see why I couldn't truncate but I
was worried that there might be something that I didn't know about. I
understand what I will lose the ability for Enterprise manager to easily do
restores.
LehrSJ
"tootsuite@.gmail.com" wrote:

> Yes, you can truncate the tables. See the system table map to see the
> relationships btwn the backup tables as there are dependencies between
> them. All you lose by truncating the tables is the ability to use EM or
> Mgmt Studio to do a restore, as it relies on the information in those
> tables when suggesting which backups to apply. If you can afford to
> lose it, no big deal. The information just gets repopluated on your
> next backup.
> Meanwhile, you might want to set up a nightly job to run
> sp_delete_backuphistory so the table growth is kept in check.
> LehrSJ wrote:
>

alternative to scptxfr?

I know that the scptxfr tool can be used for scheduling scripting. However,
I would like to be able to determise what gets scripted out and what
doesn't. Is there another way?
--
SQL2K SP3
TIA, ChrisRUse DMO from your own code?
http://www.karaszi.com/SQLServer/info_generate_script.asp
Tibor Karaszi, SQL Server MVP
http://www.karaszi.com/sqlserver/default.asp
http://www.solidqualitylearning.com/
http://www.sqlug.se/
"ChrisR" <bla@.noemail.com> wrote in message news:%231jJ9kFEFHA.2608@.TK2MSFTNGP10.phx.gbl...
>I know that the scptxfr tool can be used for scheduling scripting. However,
> I would like to be able to determise what gets scripted out and what
> doesn't. Is there another way?
> --
> SQL2K SP3
> TIA, ChrisR
>|||I just saw the earlier post "generating database script" and that'll do it.
Thanks.
"ChrisR" <bla@.noemail.com> wrote in message
news:#1jJ9kFEFHA.2608@.TK2MSFTNGP10.phx.gbl...
> I know that the scptxfr tool can be used for scheduling scripting.
However,
> I would like to be able to determise what gets scripted out and what
> doesn't. Is there another way?
> --
> SQL2K SP3
> TIA, ChrisR
>

alternative to scptxfr?

I know that the scptxfr tool can be used for scheduling scripting. However,
I would like to be able to determise what gets scripted out and what
doesn't. Is there another way?
SQL2K SP3
TIA, ChrisRUse DMO from your own code?
http://www.karaszi.com/SQLServer/in...rate_script.asp
Tibor Karaszi, SQL Server MVP
http://www.karaszi.com/sqlserver/default.asp
http://www.solidqualitylearning.com/
http://www.sqlug.se/
"ChrisR" <bla@.noemail.com> wrote in message news:%231jJ9kFEFHA.2608@.TK2MSFTNGP10.phx.gbl...[
vbcol=seagreen]
>I know that the scptxfr tool can be used for scheduling scripting. However,
> I would like to be able to determise what gets scripted out and what
> doesn't. Is there another way?
> --
> SQL2K SP3
> TIA, ChrisR
>[/vbcol]|||I just saw the earlier post "generating database script" and that'll do it.
Thanks.
"ChrisR" <bla@.noemail.com> wrote in message
news:#1jJ9kFEFHA.2608@.TK2MSFTNGP10.phx.gbl...
> I know that the scptxfr tool can be used for scheduling scripting.
However,
> I would like to be able to determise what gets scripted out and what
> doesn't. Is there another way?
> --
> SQL2K SP3
> TIA, ChrisR
>