sql

How can I restore a SQL Server database using SMO with full text catalogues?

Hi, I want to programatically (c#) restore a database (SQL Server 2008) which was originally from my live environment. My local environment is obviously quite different, with different drive mappings. I have followed this article (http://www.mssqltips.com/tip.asp?tip=1849) which has been a great help, but I am struggling to find out h...

Database mirroring: "witness" server what is it for?

What is a witness server used for? Why use it? ...

MySQL trigger loop

Hey all I am going through the pain stacking process of sorting out someone else code. So I am decided to recreate a new database to sit alongside the old one then to use triggers to transfer data between both tables. Now I have an issue with a it looping IE A trigger on each table to update the other. Once one updates it should upda...

SQL Pivot table error-using variable gives syntax error

Hi my coworker came to me with this error and now I am hooked and trying to figure it out, hope some of the experts can help us! Thanks so much! When I execute Step6 we get this error: Msg 102, Level 15, State 1, Line 4 Incorrect syntax near '@cols'. --Sample of pivot query --Creating Test Table Step1 CREATE TABLE Product(Cust VARC...

MySQL db Audit Trail Trigger

I need to track changes (audit trail) in certain tables in a MySql Db. I am trying to implement the solution suggested here. I have an AuditLog Table with the following columns: AuditLogID, TableName, RowPK, FieldName, OldValue, NewValue, TimeStamp. The mysql stored procedure is the following (this executes fine, and creates the proce...

Return segmented average from SQL Query?

Hi, I measure the load on DNS servers every minute and store that into an SQL DB. I want to draw a chart of the load for the last 48 hours. That's 69120 (48*24*60) data points but my chart's only 800 pixels wide so to make things faster I would like my SQL query to return only ~800 data points. It's seems to me like a pretty standard t...

SQL Dynamic query for searching

I am working on a problem that I'm certain someone has seen before, but all I found across the net was how not to do it. Fake table example and dynamic searching. (Due to my low rating I cannot post images. I know I should be ashamed!!) Clicking the add button automatically creates another row for adding more criteria choices. (Note...

Excel and SQL, order by help

Im stuck in Excel 2007, running a query, it worked until I wanted to add a 2nd row containing "field 2". Select "Site Updates"."Posted By", "Site Uploaded"."Site Upload Date" From site_info.dbo."Site Updates" Where ("Site Updates"."Posted By") AND "Site Uploaded"."Site Upload Date">={ts '2010-05-01 00:00:00'}), ("Site Location"='Chicago...

Passing a DataTable into a Stored Procedure. Is there a better way?

Can A datatable somehow be passed into SQL Server 2005 or 2008 ? I know the standard way seesm to be passing XML to a SP. And a datatable can easily be converted to XML somehow to do that. What about passing a .NET object into a SP ? Is that possible ? I remember hearing about SQL and CLR working together in 2008 somehow but I never...

I'm looking for a reliable way to verify T-SQL stored procedures. Anybody got one?

Hi all-- We're upgrading from SQL Server 2005 to 2008. Almost every database in the 2005 instance is set to 2000 compatibility mode, but we're jumping to 2008. Our testing is complete, but what we've learned is that we need to get faster at it. I've discovered some stored procedures that either SELECT data from missing tables or try to...

How to include many "sub"-queries in a SQL statement to generate file paths for images?

Greetings, Using this Query to extra data to CSV file from customized OS Commerce mySQL db. SELECT products_id, max( if( products_extra_fields_id = '1', products_extra_fields_value, 0 ) ) AS band_avail, max( if( products_extra_fields_id = '2', products_extra_fields_value, 0 ) ) AS 1_gal_avail, max( if( products_extra_fields_id = '3', ...

convert to UDF from select statement

How would one go about converting this into a scalar UDF? I'll pass the product_id to the UDF. Running SQL 2k5 SELECT sum(qty) as qty, product_id FROM vProductQuantity WHERE product_id = @product_id GROUP BY product_id ...

Delete all records that have no foreign key constraints

I have a SQL 2005 table with millions of rows in it that is being hit by users all day and night. This table is referenced by 20 or so other tables that have foreign key constraints. What I am needing to do on a regular basis is delete all records from this table where the "Active" field is set to false AND there are no other records in ...

Eliminate duplicates in SQL query

i have a table with 6 fields. the columns are ID, new_id price,title,Img,Active. I have datawhich is duplicated for the price column. When I do a select i want to show only distinct rows where new_id is not the same. e.g.- ID New_ID Price Title Img Active 1 1 20.00 PA-1 0X4... 1 2 1 10.00 PA-10 ...

Why are there performance differences when a SQL function is called from .Net app vs when the same call is made in Management Studio

We are having a problem in our test and dev environments with a function that runs quite slowly at times when called from an .Net Application. When we call this function directly from management studio it works fine. Here are the differences when they are profiled: From the Application: CPU: 906 Reads: 61853 Writes: 0 Duration: 926 ...

(SQL) Selecting from a database based on multiple pairs of pairs

The problem i've encountered is attempting to select rows from a database where 2 columns in that row align to specific pairs of data. IE selecting rows from data where id = 1 AND type = 'news'. Obviously, if it was 1 simple pair it would be easy, but the issue is we are selecting rows based on 100s of pair of data. I feel as if there mu...

I'm trying to handle the updates on 2 related tables in one DetailsView using Jquery and Linq, and having trouble with adding and removing related entries

Given two related tables (reports, report_fields) where there can be many report_fields entries for each reports entry, I need to allow the user to enter new report_fields, delete existing report_fields, and re-arrange the order. Currently I am using a DetailsView to handle the editing of the reports. I added some logic to handle repor...

More FP-correct way to create an update sql query

I am working on access a database using F# and my initial attempt at creating a function to create the update query is flawed. let BuildUserUpdateQuery (oldUser:UserType) (newUser:UserType) = let buf = new System.Text.StringBuilder("UPDATE users SET "); if (oldUser.FirstName.Equals(newUser.FirstName) = false) then buf.Append("S...

SQL string manipulation to return multiple rows

I'm an experienced programmer, but relatively new to SQL. We're using Oracle 10 and 11. I have a system in place using SQL that combines actual rows with virtual rows (e.g. "SELECT 1 from DUAL") doing unions and intersects as needed, which all seems to work. My problem is that I need to combine this system which is expecting rows of d...

SQL Server Express performance issue

Hi folks ! I know my questions will sound silly and probably nobody will have perfect answer but since I am in a complete dead-end with the situation it will make me feel better to post it here. So... I have a SQL Server Express database that's 500 Mb. It contains 5 tables and maybe 30 stored procedure. This database is use to store a...