Table Join between Servers

I need to compare result sets from different servers. The tables I want data from share a primary key. Question: Because I have a primary key, can I query data using a simple join (ie ‘Server1.db1.dbo.table1.primarykeyfield = Server2.db2.dbo.table2.primarykeyfield) without having to use the stored proc (sp_addlinkedserver) ?

PHP and SQLSRV isn't inserting all the rows it should

I’m utilizing PHP 5.5 and connecting to a MS SQL database. Connection works as expected. I’m attempting to do a mass insert (around 2000 rows). Rather than using PHP to run 2000 INSERT statements, I’m sending a query like so: DECLARE @count INT SET @count = 0 WHILE(@count < 2000) BEGIN INSERT INTO Table (Field1, […]

conditional where statement in tsql?

I have two parameters that I want to filter by, If competitorID is null or zero then I should filter the set against all competitor ids in another table else I should filter against competitorID. I have written the following but it is wrong as it filters against all the competitors. SELECT * FROM DashboardDataCache […]

Best way to insert 15.000 records on sql server 2012?

What’s the best way to insert 15.000 records or more in sql server 2012? Store procedure? Pure inserts? I’m using a .NET application in C# by the way.

Inner Join and Group By in SQL with out an aggregate function.

I am trying to retrieve data from 2 table with some conditions. When I just do the inner join with the conditions , I get a huge value (200000 data). But when I group by I get a very less value like (8000 data). SELECT Tcg.SK_tID, Tcg.SK_ServiceProviderID INTO #CHDetails FROM #ClientGroup Tcg INNER JOIN dbo.Component […]

Is there any potential performance problems if I update by deleting and inserting

I’m using SQL Server and I have a table related N-1 to another table and I have a process that updates the information of the N table by removing all the related rows and inserting them again. I could do a search in the table and check if the row I’m going to insert already […]

Delete table rows in loop

We are using SQL Server 2000. We have a heavy database with over 100000 images. Currently I’m deleting records with this query: DELETE FROM T_JBSHEETDATA WHERE (F_JBREF NOT IN (SELECT JOB_REF_NUMBER FROM T_JBDTLS)) but unfortunately it only deletes 500 records at a time. If I take more records the server dies (server timeout). How do […]

System.Data.SqlClient.SqlException

protected void Button1_Click(object sender, EventArgs e) { if (TextName.Text != “” && TextPass.Text != “” && TextRePass.Text != “” && TextAddr.Text != “” && TextPhn.Text != “”) { SqlConnection i = new SqlConnection(@”Data Source=.\SQLEXPRESS;AttachDbFilename=E:\Study materials\Mobile Shop\App_Data\;Integrated Security=True;User Instance=True”); i.Open(); string q = “insert into Register values (‘” + TextName.Text + “‘,'” + TextRePass.Text + “‘,'” […]

Need a stored procedure to find missing gaps and insert rows

I have a small dev challenge here. I have the following table CURR_RATES in SQL Server: SELECT * FROM (VALUES (1001300, ‘USD’, 13, ‘8/1/2013’, 1.31), (1001301, ‘USD’, 13, ‘8/2/2013’, 1.32), (1001302, ‘USD’, 13, ‘8/5/2013’, 1.33), (1001303, ‘USD’, 13, ‘8/6/2013’, 1.34), (1001304, ‘USD’, 13, ‘8/7/2013’, 1.35), (1001305, ‘USD’, 13, ‘8/8/2014’, 1.31), (1001306, ‘USD’, 13, ‘8/9/2013’, 1.32), […]

How to create a flexible query for XML stored in SQL table

I have the following XML file that is copied in my database <ns2:procedure1 xmlns:ns2=”http://www.endpoint.com/”> <auth> <company>TEST Company</company> <lineOfBusiness>Sales</lineOfBusiness> <caseNumber>00001</caseNumber> <creationDate>2013-12-04</creationDate> <reviews> <reviews> <reviewNumber>ZA1010</reviewNumber> <revision>1</revision> <sequence>1</sequence> </reviews> <reviews> <reviewNumber>ZA1010</reviewNumber> <revision>2</revision> <sequence>2</sequence> </reviews> <reviews> <reviewNumber>ZA1010</reviewNumber> <revision>3</revision> <sequence>3</sequence> </reviews> </reviews> </auth> </ns2:procedure1 xmlns:ns2=”http://www.endpoint.com/”> I am using the following code: DECLARE @XML AS XML DECLARE @hDoc AS INT DECLARE […]

MS SQL Server is a Microsoft SQL Database product, include sql server standard, sql server management studio, sql server express and so on.