sql-server

Replace multiple instances in select statement

User SQLServer 2005 Here is an example of string I'm stuck with: {\rtf1\ansi\ansicpg1252\deff0\deflang1033{\fonttbl{\f0\fnil\fcharset0 Arial Rounded MT Bold;}{\f1\fnil\fcharset0 Arial;}} \viewkind4\uc1\pard\f0\fs54 1000\f1\fs20\par } I want to replace any font name with 'Times New Roman' I can get the first one with (textlong1 is ...

sql server table fast load isn't

I've inherited an SSIS package which loads 500K rows (about 30 columns) into a staging table. It's been cooking now for about 120 minutes and it's not done --- this suggests it's running at less than 70 rows per second. I know that everybody's environment is different but I think this is a couple orders of magnitude off from "typical"....

security libraries for SQL Server

I have some extended classes (utilizing both HMAC and cryptographic tech), and I'm hoping to utilize them for a new product's database from said database's stored procedures (inclusive of time logging, user-event logging, etc.) under SQL Server. Can anyone recommend a resource detailing the best ways to achieve this or optionally advise...

Calculate a Running Total in SqlServer

Imagine the following table (called TestTable): id somedate somevalue -- -------- --------- 45 01/Jan/09 3 23 08/Jan/09 5 12 02/Feb/09 0 77 14/Feb/09 7 39 20/Feb/09 34 33 02/Mar/09 6 I would like a query that returns a running total in date order, like: id somedate somevalue ...

How do I use the results of a stored procedure from within another?

I have a stored procedure that I want to call from within another, and then loop through the results. Sort of like using a cursor with a stored procedure rather than a SQL select statement. I can't quite figure out how to do it. I can get the whole result like this: DECLARE @result int; EXEC @result = sp_who; PRINT @result; Interesti...

How can I restore SQL Server 2000 from corrupted backup files?

I am using SQL Server 2000. I have a corrupted backup file. How can I restore the database from that corrupted backup file? Any help or suggestions really appreciated. ...

Summing the values from the 2nd table based on ID of the 1st table

I have done this query before, but for some reason I always have to dig the answer up. Can someone explain the solution for me so I can finally 'get it'! (thanks!) Table#1 Employees (employeeID, username) Table#2 Sales (saleID, employeeID, amount) Question: List all the employees, along with the total # (count) of sales they have. ...

How to restore database using sqb files in SQL SERVER

Hi,Everyone: I have a file with sqb extension(e.g: clark.sqb),how should i to restore database using the sqb file.thanks! ...

More efficient of the two queries?

I have a table with columns user_id, email, default. Default stores 'Y' or 'N' depending if the email is the users default email. Each user can have only one default email. When a user is doing an update or insert on the table, in my SP I check if the user has passed isDefault as 'Y'. If so, I need to update all the entries for that us...

How to alter a primary key in an SQL Server 2005 database without losing any data?

I have one table in my database that has a primary key and its data type is varchar(10) but it stores only 5 char, so I want to change its data type from varchar(10) to varchar(5) without losing any data. Currently I'm creating a temp table, moving data from the original table to the temp table, then altering it, and lastly restoring th...

How to avoid the "divide by zero" error in SQL?

I hate this error message: Msg 8134, Level 16, State 1, Line 1 Divide by zero error encountered. What is the best way to write SQL code, so that I will never see this error message again? I mean, I could add a where clause so that my divisor is never zero. Or I could add a case statement, so that there is a special treatment for zer...

C#, Linq2SQL: How long should CommandTimeout be and where should it be set?

We are using C# and Linq2SQL to get data from a database for some reports. In some cases this takes a while. More than 30 seconds, which seems to be the default CommandTimeout. So, I guess I have to up the CommandTimeout. But question is, how much? Is it bad to just set it very high? Wouldn't it be bad if a customer was trying to do so...

Calculating DB backup size

Is there a way to know the size of a database full backup file before we actually do the backup? I did some analyses and figured sp_spaceused could give a close figure but thats not all, there seem(s) to be one/more factors other than the used space that go into determining the size? Has anyone been down this path before? Any ideas? ...

Avoid hardcoding when changing values in SQL Server trigger

I have a sql server "instead of insert" trigger that populates a single column (PromoCode). It all works perfectly, but I don't like the fact I have had to hardcode the columns in actual INSERT statement: CREATE TRIGGER PopulateOrderPromoCode ON Order INSTEAD OF INSERT AS BEGIN --// Get the Promo Code DECLARE @PromoCode int; ...

Excel add-in transferring data from sheets to database: file path problem

I wish to create an addin for excel which can read the current sheets data and then insert it into database. The database connection requires the file location. Therefore that approach cant be applied as I have to send the file that I have currently opened and can't specify the file path. And moreover I need the data of each column to ...

Redefining the Data Link between a MS Access file and SQL Server

I have a pretty standard database sitting on SQL Server. To manage the data (instead of creating a solution using an IDE) I've linked to the database using MS-Access (4 users as a start. I'm testing a concept and a full solution can be developed once there's enough data). *MS-Access > New file > Project using exiting data... *Specify SQ...

How can i evaluate this query?

This query give me error:Msg 156, Level 15, State 1, Line 10 Incorrect syntax near the keyword 'where'. declare @date1 datetime,@date2 datetime , @COUNT INT , @countgap int, @order int seLECT @date1='2009-05-11' , @date2 = '2009-05-12' seLECT @countgap = 30 , @COUNT = 0, @order=23 select VisitingCount from ( select count(page) as Visi...

track all the versions of stored procedure which is modified multiple times.

If a stored procedure is modified 10 times , i want to log or track it in a table in a column in 10 rows from initial stored procedure to the latest that is 10 different versions of the same stored procedure , could any one suggest how to do this? ...

SQL Help With Query - Group By and Aggreate Functions

Hi guys, I have a query I need some help with, have been checking out a fair few tutorials but nohting I found covers this issue. I have three joined tables, Products,ProductImagesLookUp and Images. A product can have any number of Images and the Order of the Images for a Product are stored in ProductImagesLookUp. I need to return...

How can I join two queries?

How can i join these two queries (Query1-Query2) Query1: declare @date1 datetime,@date2 datetime , @COUNT INT , @countgap int seLECT @date1='2009-05-11' , @date2 = '2009-05-12' seLECT @countgap = 30 , @COUNT = 0 select @date1 TARIH , @COUNT SIRA INTO #TMP WHILE @date1 < @date2 BEGIN SELECT @date1 = DATEadd(minute,@countgap...