Showing posts with label tsql. Show all posts
Showing posts with label tsql. Show all posts

Wednesday, March 21, 2012

R

Hi,

I am using Sql Server 2005 64bit on a quad processor server with 6GB memory. When I run a some TSQL that uses a cusor the average processor never goes too much above 25%. Memory using is about 300-400K for sql server.

Using perfmon it appears the disk queue length is 0 (or very close to it), can anyone suggest some perfcounters that would help me identify why my sql box isn't flying?

Thanks for your help

Graham

I highly recommend you read this excellent whitepaper.
http://www.microsoft.com/technet/prodtechnol/sql/2005/tsprfprb.mspx

Tuesday, March 20, 2012

Quick Update/Insert TSQL?

Hi all!

I have a quick question...

'UPLOAD / INSERT EXISTING CLIENT DATA INTO SQL SERVER FROM CLIENT
INSERT INTO ProductLocal
(tblID,SQLkey, CreateDateTime, Alias, ProductNumber, ProductMfgID, ProductDesc, ProductAlt1Number, ProductAlt2Number, ProductCost,
ProductListPrice, ProductVendorID, ProductHier1, ProductHier2, ProductHier3, ProductHier4, ProductHier5, ProductHier6, ProductHier7, ProductHier8,
ProductHier9, ProductCategory, ProductSubCategory, ProductLocalAdd, ProductAddDesc, create_timestamp, update_timestamp, update_originator_id,
create_date)
SELECT tblID, SQLkey, CreateDateTime, Alias, ProductNumber, ProductMfgID, ProductDesc, ProductAlt1Number, ProductAlt2Number, ProductCost,
ProductListPrice, ProductVendorID, ProductHier1, ProductHier2, ProductHier3, ProductHier4, ProductHier5, ProductHier6, ProductHier7, ProductHier8,
ProductHier9, ProductCategory, ProductSubCategory, ProductLocalAdd, ProductAddDesc, create_timestamp, update_timestamp, update_originator_id,
create_date
FROM Product
WHERE (Alias = 'me')

'DOWNLOAD / UPDATE-INSERT EXISTING LOCAL DB (PRODUCT TABLE) FROM SQL SERVER PRODUCTLOCAL TABLE

What would be the best and least expensive way to UPDATE/INSERT the local client db from the SQL Server?

-- LOCAL DB (PRODUCT TABLE) FROM SQL SERVER PRODUCTLOCAL TABLE

Any help would be appreciated.... thanks.

Kind regards,

billb

You can use the following approaches,

1. Linked Server,

Set up Linked Serer on your Local Server,

EXEC master.dbo.sp_addlinkedserver

@.server = N'<LinkedServerName>',

@.srvproduct=N'SQLOLEDB.1',

@.provider=N' SQLOLEDB.1',

@.datasrc=N'<YourServer>',

@.provstr=N'Provider=SQLOLEDB.1;Data Source=<YourServer>;Initial Catalog=<Database name>’,

@.catalog=N'<Database Name>'

GO

Exec sp_addlinkedsrvlogin

@.rmtsrvname = N'<LinkedServerName>',

@.useself = false,

@.locallogin = 'sa',

@.rmtuser = 'sa',

@.rmtpassword = '***************'

Now execute the following query..

INSERT INTO ProductLocal

SELECT *

FROM

<LinkedServerName>.<databasename>.<dbo>.Product

2. Ad-Hoc Distributed Quires

Insert Into ProductLocal

SELECT a.*

FROM OPENROWSET('MSDASQL','DRIVER={SQL Server}; SERVER=<YourServer>; UID=sa; PWD=PASSWORD’, 'Select * from <databasename>.dbo.product') AS a;

3. SQL Server Replication

See, http://msdn2.microsoft.com/en-us/library/ms151198.aspx

|||

Was sort of going for just the TSQL Update/Insert though:

Insert Into ProductLocal

SELECT a.*

FROM OPENROWSET('MSDASQL','DRIVER={SQL Server}; SERVER=<YourServer>; UID=sa; PWD=PASSWORD’, 'Select * from <databasename>.dbo.product') AS a;

Something like:

Update ProductLocal

SELECT a.*

FROM OPENROWSET('MSDASQL','DRIVER={SQL Server}; SERVER=<YourServer>; UID=sa; PWD=PASSWORD’, 'Select * from <databasename>.dbo.product where alias = ' & me & ' & ') AS a;

Not sure how to do the above update tsql...

Thanks,

billb

Quick TSQL?

Hey all... I have a few tables that I am joining and need to know how to set a value from the return to a different column:

example:

SELECT

Prospect.ProspectName AS P1, AccountShipTo.ShipToName AS [Account Name], ProposalHeader.PropHCity AS City, ProposalHeader.PropHState AS State,

ProposalHeader.PropHNumb AS [Proposal ID], ProposalHeader.PropHRevNumb AS Rev, ProposalHeader.PropHCreateDate AS [Creation Date],

ProposalHeader.update_timestamp AS [Last Edit Date]

FROM ProposalHeader LEFT OUTER JOIN

AccountShipTo ON ProposalHeader.PropHShipTo = LTRIM(AccountShipTo.ShipToCust) LEFT OUTER JOIN

Prospect ON ProposalHeader.PropHBillTo = LTRIM(Prospect.ProspectNumb)

WHERE (ProposalHeader.Alias = N'billb')

GROUP BY ProposalHeader.PropHRevNumb, AccountShipTo.ShipToName, ProposalHeader.PropHCity, ProposalHeader.PropHState,

ProposalHeader.PropHNumb, ProposalHeader.PropHCreateDate, ProposalHeader.update_timestamp, Prospect.ProspectName

ORDER BY [Proposal ID]

I need P1 value (Test - Timberline Corp)to be in the Account Name column (NULL)... any ideas?

P1 Account Name City State Proposal ID Rev Creation Date Last Edit Date

NULL Samples, Inc. High Point NC Samples1 1 2007-07-25 2007-07-30

Test - Timberline Corp NULL Rapid City SD test1 1 2007-07-31 2007-07-31

(2 row(s) affected)

Any help would be appreciated... thanks!

Have you tried coalesce(AccountShipTo.ShipToName, Prospect.ProspectName) or isnull(AccountShipTo.ShipToName, Prospect.ProspectName)
|||

Very coo! Thanks... Smile

Did this....

SELECT COALESCE (AccountShipTo.ShipToName, Prospect.ProspectName) AS [Account Name]

Friday, March 9, 2012

Quick Question on Transactions

Hi all,
I have a simple TSQL question that I'm hoping someone can help with.
In the following query:
BEGIN TRANSACTION
UPDATE Properties
SET EstateID = null
WHERE Properties.EstateID = @.ID
DELETE FROM Estates
WHERE [ID] = @.ID
COMMIT TRANSACTION
I'm wondering, if there is some sort of error, will a rollback occur automat
ically
or do I need to put in some sort of error handling code and an explicit roll
back
command?
Any advice would be much appreciated
Kindest Regards
SimonCheck out SET XACT_ABORT in BOL|||Erland Sommarskog has two great (=must-read) articles on error-handling:
http://www.sommarskog.se/error-handling-I.html
http://www.sommarskog.se/error-handling-II.html
ML
http://milambda.blogspot.com/